23. 有如下的程序: Private Sub Command1_Click() Dim k As Integer,m As Integer Dim P As Integer k=4:m=1 P=Fun(k,m):Print P: P=Fun(k,m):Print P End Sub Private Function Fun(a As Integer,b As Integer) Static m As Integer,i As Integer m=5:i=2 i=i+m+1 m=i+a+b Fun=m\2 End Function 单击命令按钮后,输出结果为。
27. 单击命令按钮时,下列程序的执行结果是。 Private Sub Command1_Click() Call BT 4 End Sub Private Sub BT(x As Integer) x=x*2+1 If x < 6 Then Call BT(x) End If x=x*2 Print X; End Sub
A.Private Sub List1_Click() Label1.Caption=List1.ListIndex List1.RemoveItem List1.Text End Sub
B.Private Sub List1_Click() Label1.Name=List1.ListIndex List1.RemoveItem List1.Text End Sub
C.Private Sub List1_Click() Label1.Caption=List1.Text List1.RemoveItem List1.ListIndex End Sub
D.Private Sub List1_Click() Label1.Name=List1.Text List1.RemoveItem List1.ListIndex End Sub
A B C D
C
[解析] Label的内容要用Caption属性,List去除项目要引用项目号。
33. 有如下函数过程: Function Fun(ByVal x As Integer,ByVal y As Integer)As Integer Do While y<>0 reminder=x Mod y x=y y=reminder Loop Fun=x End Function 以下调用函数的事件过程,该程序的运行结果是。 Private Sub Command7_Click() Dim a As Integer,b As Integer a=100:b=25 x=Fun(a,B) Print X End Sub
7. 以下是一个比赛评分程序。在窗体上建立一个名为Text1的文本框数组,然后画一个名为Text2的文本框和名为Command1的命令按钮。运行时在文本框数组中输出7个分数,单击“计算得分”命令按钮, 则最后得分显示在Text2文本框中(去掉一个最高分和一个最低分后的平均分即为最后得分)请将程序补充完整。 Private Sub Command1_click() Dim k As Integer Dim sum As Single,max As Single,min As Single Sum=Text1(0) max=Text1(0) min= For k=1 To 6 If max c Text1(k)Then max= Text1(k) End If If min>Text1(k) Then min=Text1(k) End If sum=sum+Text1(k) Next k Text2=(sum-max-min)/5 End Sub
9. 下列程序计算Sn的值。Sn=a+aa+aaa+…+aaa…a,其中最后一项为n个a。 例如:a=5,n=4时,则Sn=5+55+555+5555。请在空白处填入适当的内容,将程序补充完整。 Private Sub Command1_Click() Dim a As Integer,n As Integer, Cout As Integer Dim Sn As Long, Tn As Long Cout=1 Sn=0 Tn=0 a=InputBox请输入a的值:“) n=InputBox请输入n的值!”) Do Tn=Tn*10+a Sn=Sn+Tn Cout=Cout+1 Debug.Print a,n,Sn End Sub
11. 在一个窗体上有一个命令按钮CmdMax。单击CmdMax时,窗体上显示“字体由小变大”,字号每次增加2。请填空。 Private Sub Form_Load() Form1.Caption=“字体变化示范” CmdMax.Caption=“字体变大” End Sub Private Sub CmdMax_Click() Form1.Print“字体由小变大” End Sub
13. 在窗体上画一个文本框,名称为Text1,然后编写如下程序: Private Sub Form_Load() Open"d:\temp\dat.txt"For Output As#1 Text1.Text:“” End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If =13 Then If UCase(Text1.Text1= Then Close#1 End Else Write#1, Text1.Text=“” End If End If End Sub 以上程序的功能是,在D盘temp目录建立1个名为dat.txt的文件,在文本框中输入字符,每次按回车键(回车符的ASCⅡ码是13)都把当前文本框中的内容写入文稿件dat.txt,并清除文本框中的内容;如果输入“END”,则结束程序。请将程序补充完整。