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/11/23 21:24:42
vb题 Private Sub Command 1 _Click()Dim x As Integerx=Val(InputBOX(
xOP6!v,ie7Z.aoͦCV'Y[x_pj \Խ.iqHZP%SѵLL']& NǢKW教,y& 5߆bRh2MZpwYfvOǠ5 򼖂|$Csk \;E8ESߨBG\@2Pw3AxOX@$s B19Á+yJCD7CQrkuy!:2tl{:?q7W/ Ϋ`'ش/n!(BNKd@mnAţ,fu|7lV9ӽeؗ:?nZN^iRܿ,hϤG{ħ~7gwNg~ G?V%ba3X!bqL ?X>LDɗNh`ʹ

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