问题
填空题
窗体上命令按钮Commandl的事件过程如下:
Private Sub Command1_Click()
Dim total As Integer
total=s(1)+s(2)
Print total
End Sub
Private Function s(m As Integer)As Integer
Static x As Integer
For i=1 To m
x=x+1
Next i
s=x
End Function
运行程序,第3次单击命令按钮Command1时,输出结果为()。
答案
参考答案:P
解析:
本题考查的考点是有关静态变量的。静态变量定义后默认值为o,并且会保存上一次为这个变量赋的值。本题第一次单击命令按钮时,调用两次s函数,第一次使得x的值为1,第二次使得x的值为3;第二次单击命令按钮时,调用两次s函数,第一次使得x的值为4,第二次使得x的值为6:第三次单击命令按钮时,调用两次s函数,第一次使得x的值为7,第二次使得x的值为9,最后结果为7+9=16。