5.運(yùn)行下列VB程序,在文本框Text1中輸入“臺(tái)州”,單擊命令按鈕Command1后彈出如圖所示的出錯(cuò)信息提示. Private Sub Command1_Click( ?。?br /> Dim City As String,file1 As String City=Text1.Text file1=City+“.jpg“ Image1.Picture=LoadPicturt(file1) List1.AddItem City End Sub 此時(shí)程序正在執(zhí)行的語句是( )
16.楊輝三角,又稱賈憲三角形,是我國古代數(shù)學(xué)的成就之一,如圖所示為楊輝三角前5行的數(shù)據(jù)排列.從圖可知,楊輝三角當(dāng)前行的數(shù)值可由前一行推導(dǎo)計(jì)算得到. 現(xiàn)要求楊輝三角第n行的數(shù)據(jù),編寫的VB程序功能如下:在文本框Text1中輸入n值(n≤30),單擊按鈕Command1后,在標(biāo)簽框Label1中輸出第n行的數(shù)據(jù).實(shí)現(xiàn)上述功能的VB程序如下,但加框處代碼有錯(cuò),請(qǐng)改正. Private Sub Command1_Click( ?。?br /> Dim pre(0 to 30)As Long,cur(0 to 30)As Long '數(shù)值型數(shù)組的數(shù)組元素初值默認(rèn)為0 Dim s As String,i As Integer,j As Integer n=Val(Text1.Text) =1'(1) For i=1 To n s=““ For j=1 To i cur(j)='(2) s=s & cur(j) &““ Next j For j=1 To i pre(j)=cur(j) Next j Next i Label1.Caption=s End Sub.
17.猜數(shù)字是一種古老的密碼破譯類益智小游戲.通常由兩個(gè)人玩,也可以由一個(gè)人和電腦玩,其標(biāo)準(zhǔn)規(guī)則為: 1)一方出數(shù)字,出數(shù)字的人要想好一個(gè)無重復(fù)數(shù)字的4位數(shù)(如0165,5234等),不能讓猜的人知道; 2)另一方猜數(shù)字,每猜一個(gè)數(shù)字,出數(shù)者根據(jù)結(jié)果給出“幾A幾B的提示”,其中A前面的數(shù)字表示位置正確的數(shù)字個(gè)數(shù),而B前面的數(shù)字表示數(shù)字正確但位置不對(duì)的數(shù)字個(gè)數(shù).(如要猜5234,猜的人給出5346,則提示1A2B); 3)重復(fù)第二步的猜測過程,直到猜中(即提示4A0B)為止. 小林編寫了一個(gè)和電腦猜數(shù)字的VB程序,其功能如下:窗體加載時(shí),調(diào)用自定義函數(shù)產(chǎn)生待猜的4位數(shù)字,并初始化猜測次數(shù).用戶在文本框Text1中輸入猜的數(shù)字,單擊“我猜”按鈕Command1,程序進(jìn)行判斷,并將結(jié)果顯示在列表框List1中.猜中后,在標(biāo)簽框Label2中根據(jù)猜測次數(shù)給出評(píng)語.程序運(yùn)行效果如1圖所示. (1)實(shí)現(xiàn)上述功能的VB程序如下,請(qǐng)?jiān)跈M線處填入合適代碼. Dim result As String,total As Integer Dim flag(0 to 9)As Boolean'標(biāo)記下標(biāo)對(duì)應(yīng)的數(shù)字是否存在,初值默認(rèn)為False Private Sub Form_Load( ?。?br /> result=
total=0 End Sub Private Sub Command1_Click( ?。?br /> Dim A As Integer,B As Integer Dim C As Integer'變量C存儲(chǔ)數(shù)字正確(含位置正確)的數(shù)字個(gè)數(shù) Dim guess As String,i As Integer,t1 As String,t2 As String guess=Text1.Text A=0:C=0 For i=1 To 4 t1=Mid(result,i,1) t2=Mid(guess,i,1) If t1=t2 Then A=A+1 If
Then C=C+1 Next i total=total+1 B=
List1.AddItem Str(total) &““& guess &““& Str(A) &“A“& Str(B) &“B“ If A=4 Then If total<=8 Then Label2.Caption=“太厲害了!您只用了“& total &“次.“ Else Label2.Caption=“繼續(xù)鍛煉!您共花了“& total &“次.“ End If End If End Sub 'RndCode 函數(shù)用于隨機(jī)產(chǎn)生待猜測的n位不重復(fù)數(shù)字字符 Function RndCode(n As Integer) As String Dim x As Integer,i As Integer Randomize num=0:RndCode=““ Do While num<n x=Int(Rnd*10)'隨機(jī)產(chǎn)生一個(gè)[0,9]的數(shù)字 If flag(x)=False Then flag(x)=True num=num+1 RndCode=RndCode & x End If Loop End Function (2)如果某次游戲過程如2圖所示,那么第7次要猜測成功,應(yīng)輸入