vb题 Private Sub Command 1 _Click()Dim x As Integerx=Val(InputBOX("输入数据"))Text1=Str(fun(x)+fun(x)+fun(x))End SubPrivate Function fun(ByRef n As Integer)If n Mod 3=0 Thenn=n+nElsen=n*nEnd Iffun=nEnd Function当
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 13:43:49
vb题 Private Sub Command 1 _Click()Dim x As Integerx=Val(InputBOX("输入数据"))Text1=Str(fun(x)+fun(x)+fun(x))End SubPrivate Function fun(ByRef n As Integer)If n Mod 3=0 Thenn=n+nElsen=n*nEnd Iffun=nEnd Function当
vb题
Private Sub Command 1 _Click()
Dim x As Integer
x=Val(InputBOX("输入数据"))
Text1=Str(fun(x)+fun(x)+fun(x))
End Sub
Private Function fun(ByRef n As Integer)
If n Mod 3=0 Then
n=n+n
Else
n=n*n
End If
fun=n
End Function
当单击命令按钮,在输入对话框中输入2时,文本框中显示的是__
答案为什么不是12?
vb题 Private Sub Command 1 _Click()Dim x As Integerx=Val(InputBOX("输入数据"))Text1=Str(fun(x)+fun(x)+fun(x))End SubPrivate Function fun(ByRef n As Integer)If n Mod 3=0 Thenn=n+nElsen=n*nEnd Iffun=nEnd Function当
和你的fun()函数的传值方式有关
ByRef传的是X的地址,X的值会因为每次调用fun()而改变
Private Function fun(ByRef n As Integer)
Text1=Str(fun(x)+fun(x)+fun(x))
Text1=Str(4+16+256)
结果为276
如果改为
Private Function fun(ByVal n As Integer)
ByVal传值方式,X的值就不会因为调用fun()而改变
结果就会是你预期的12