阅读下列程序: Dim SW As Boolean Function func(X As Integer)As Integer If X<20 Then Y=X Else Y=20+X

admin2009-02-13  19

问题 阅读下列程序:    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 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    Private Sub Command1_Click()        Dim intNum As Integer        intNum=InputBox(" ")        If SW Then           Print func(intNum)        End If    End Sub    程序运行后,单击一次窗体,再单击命令按钮,将显示一个输入对话框,如果在对话框中输入20,则程序的输出结果为

选项 A、0
B、20
C、40
D、无任何输出

答案4

解析 上述程序由一个通用过程和3个事件过程组成,在命令按钮事件过程中调用通用过程,并将一个参数传送给通用过程。这里要注意,只有在一定的条件下,才能调用通用过程,这个条件就是,窗体的Boolean变量SW的值必须为 True,否则不能调用。而为了使SW的值为True,必须执行Form MouseUp事件过程,这只能通过单击窗体来实现。单击窗体时,按下鼠标左键执行FormMouseDown事件过程,使得SW=False,松开鼠标后执行Form MouseUp事件过程,使得 =True。程序运行后,由于单击了一次窗体,执行了Form_Mouseup事件过程,再单击命令按钮,因而SW的值为True,调用通用过程后,在窗体上显示的内容是40。若没有事先单击窗体,而直接单击按钮,窗体上就没有任何内容输出。
转载请注明原文地址:https://kaotiyun.com/show/Ys1p777K
0

随机试题
最新回复(0)