问题
填空题
窗体上命令按钮Command1的事件过程如下:
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
运行程序,第三次单击命令按钮Command1时,输出结果为______。
答案
参考答案:P
解析: 用static定义了静态变量x,在离开函数s时x保持原有的值不变,因此3次单击后输出16。