一道二级VB题的不解

来源:百度知道 编辑:UC知道 时间:2024/05/14 19:48:35
(34)在窗体上画一个名称为Command1的命令按钮,然后编写如下程序:
Dim SW As Boolean
Function func(X As Integer) As Integer
If X < 20 Then
Y = X
Else
Y = 20 + X
End If
func = Y
End Function
Private Sub Command1_Click()
Dim intNum As Integer
intNum = InputBox("")
If SW Then
Print func(intNum)
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
SW = False
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
SW = True
End Sub
程序运行后,单击命令按钮,将显示一个输入对话框,如果在对话框中输入25,则程序的执行结果是:
A)输出0
B)输出25
C)输出45
D)无任何输出
这道题目为什么说"SW声明未使用,为默认值False,print语句没运行"?

如果你在窗体上点下鼠标,就会有输出。
因为定义后WS为假,但在窗体上按下鼠标为假,抬起鼠标为真,为真以后再点按钮,输入25,会输出45。

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
上面这个两个都是鼠标在窗体上的单击事件 不点窗体就不能触发这两个事件,所以SW就是默认的False,所以就不会有结果输出