21.在窗体上画一个命令按钮(其Name属性为Command1),然后编写如下代码: Option Base 1 Private Sub Command1_Click() Dim a s=0 a=Array(1,2,3,4) j=1 For i=4 To 1 Step -1 s=s+a(i)*j j=j*10 Next i Print s End Sub 运行上面的程序,单击命令按钮,其输出结果是 A、4321 B、1234 C、34 D、12
A B C D
22.在窗体上画一个名称为Text1的文本框,要求文本框只能接收大写字母的输入。以下能实现该操作的事件过程是 A、Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii<65 Or KeyAscii>90 Then MsgBox"请输入大写字母" KeyAscii=0 End If End Sub B、Private Sub Text1_KeyDown(KeyCode As Integer,Shift As Integer) If KeyCode<65 Or KeyCode>90 Then MsgBox"请输入大写字母" KeyCode=0 End If End Sub C、Private Sub Text1_MouseDown(Button As Integer,Shift As Integer,X As Single,Y As Single) If Asc(Text1.Text)<65 Or Asc(Text1.Text)>90 Then MsgBox"请输入大写字母" End If End Sub D、Private Sub Text1_Change() If Asc(Text1.Text)>64 And Asc(Text1.Text)<91 Then MsgBox"请输入大写字母" End If End Sub
A B C D
23.假定在窗体(名称为Form1)的代码窗口中定义如下记录类型: Private Type animal animalName As String*20 aColor As String*10 End Type 在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程: Private Sub Command1_Click() Dim rec As animal Open "c:\vbTest.dat" For Random As #1 Len=len(rec) rec.animalName="Cat" rec.aColor="White" Put #1,,rec Close #1 End Sub 则以下叙述中正确的是 A、记录类型animal不能在Form1中定义,必须在标准模块中定义 B、如果文件c:\vbTest.dat不存在,则Open命令执行失败 C、由于Put命令中没有指明记录号,因此每次都把记录写到文件的末尾 D、语句“Put #1,,rec”将animal类型的两个数据元素写到文件中
A B C D
24.在窗体上画一个名称为Text1的文本框,一个名称为Command1的命令按钮,然后编写如下事件过程和通用过程: Private Sub Command1_Click() n=Val(Text1.Text) If n\2=n/2 Then f=f1(n) Else f=f2(n) End If Print f;n End Sub
Public Function f1(ByRef x) x=x*x f1=x+x End Function
Public Function f2(ByVal x) x=x*x f2=x+x+x End Function 程序运行后,在文本框中输入6,然后单击命令按钮,窗体上显示的是 A、72 36 B、108 36 C、72 6 D、108 6
A B C D
25.在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程: Private Sub Command1_Click() c=1234 c1=Trim(Str(c)) For i=1 To 4 Print ____ Next End Sub 程序运行后,单击命令按钮,要求在窗体上显示如下内容: 1 12 123 1234 则在下划线处应填入的内容为 A、Right(c1,i) B、Left(c1,i) C、Mid(c1,i,1) D、Mid(c1,i,i)