命令按钮Command1的单击事件过程如下: Private Sub Command1_Click()   x=10   Print f(x) End Sub Private Function f(y As Integer)   f=y * y End F

admin2015-06-30  24

问题 命令按钮Command1的单击事件过程如下:
Private Sub Command1_Click()
  x=10
  Print f(x)
End Sub
Private Function f(y As Integer)
  f=y * y
End Function
运行上述程序,如下叙述中正确的是(  )。

选项 A、程序运行出错,x变量的类型与函数参数的类型不符
B、在窗体上显示100
C、函数定义错,函数名f不能又作为变量名
D、在窗体上显示10

答案A

解析 变量x在按钮单击事件过程中没有定义,因此系统自动将它定义为Variant类型,由于过程中参数类型为Integer,所以程序运行时会提示"ByRef参数类型不符"错误。A选项正确。只在按钮事件中加上Dim x as Integer就可以解决问题,或者f过程中的y as integer改为ByVal y as integer也可以解决。
转载请注明原文地址:https://kaotiyun.com/show/x0Qp777K
0

最新回复(0)