全部题库 / VB / 试题详情
单选题 VB
2013-08-15

窗体上有一-个Text1文本框,一个Command1命令按钮,并有以下程序:

Private Sub Command1 Click(  )
Dim n
If Text1.Text<>"123456"Then
n=n+1
Print"口令输入错误”&n&”次"
End If
End Sub

希望程序运行时得到左图所示的效果,即:输入口令,单击“确定口令’’命令按钮,若输入的口令不是“123456”,则在窗体上显示输入错误口令的次数。但上面的程序实际显示的是右图所示的效果,程序需要修改。下面修改方案中正确的是(  )。

A.在Dim n语句的下面添加一句:n=0
B.把Print“口令输入错误”&n&“次”改为Print“口令输入错误”+n+“次”
C.把Print“口令输入错误”&n&“次”改为Print“口令输入错误”&Str(n)&“次”
D.把Dim n改为Static n

参考答案

D

答案解析

D。【解析】本题要实现的功能是当输入错误口令时,在窗体上显示输入错误口令的次数,本题若要正确记录输入错误的次数,应把n定义成静态变量n。

你可能感兴趣的试题

A.Private Sub P1 MouseMove(Button As Integer,Shift As Integer,X As Single,Y
As Single)
Print X Y
End Sub
B.Private Sub P1 MouseDown(Button As Integer,Shift As Integer,X As Single,Y
As Single)
Picture.Print X,Y
End Sub
C.Private Sub P1 MouseMove(Button As Integer,Shift As Integer,X As Single,Y
As Single)
P1.Print X,Y
End Sub
D.Private Sub Form MouseMove(Button As Integer,Shift As Integer,X As Single,Y
As Single)
P1.Print X,Y
End Sub