VB 全局变量问题:麻烦解释一下运行过程,以及说明结果为什么是9 1 4 9(很急,在线等!)
PublicaAsInteger,bAsInteger,cAsIntegerPrivateFunctions()AsIntegerDimaAsInteger,bAsInt...
Public a As Integer, b As Integer, c As Integer
Private Function s() As Integer
Dim a As Integer, b As Integer
a = a * a
Me.b = Me.b * Me.b
c = c * c
s = a + b + c
End Function
Private Sub Form_Click()
Dim sum As Integer
a = 1: b = 2: c = 3
sum = s()
Print sum; a; b; c
End Sub 展开
Private Function s() As Integer
Dim a As Integer, b As Integer
a = a * a
Me.b = Me.b * Me.b
c = c * c
s = a + b + c
End Function
Private Sub Form_Click()
Dim sum As Integer
a = 1: b = 2: c = 3
sum = s()
Print sum; a; b; c
End Sub 展开
2个回答
展开全部
因为你在Function s里定义了a和b,所以在这中间出现的所有a 和 b都是该函数范围内定义的a,b
me.b 使用的是public变量b
因为函数里没定义 c,所以c就是public变量c
sum=s
a=a*a (a=0 函数内的a)
me.b=me.b^2 (public b=2^2=4)
c=c*c(public c , c=9)
s=a(private, 0) + b(private, 0) + c(public 9)
所以 返回值 是1 4 9
me.b 使用的是public变量b
因为函数里没定义 c,所以c就是public变量c
sum=s
a=a*a (a=0 函数内的a)
me.b=me.b^2 (public b=2^2=4)
c=c*c(public c , c=9)
s=a(private, 0) + b(private, 0) + c(public 9)
所以 返回值 是1 4 9
追问
s=a(private, 0) + b(private, 0) + c(public 9)
为什么a(private, 0)、b(private, 0)????详细一点,我是新手,谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询