VB 为什么Print出来的第二行是0,第三行是4 a(1)不应该 = f(1)= 2 a(4)= f(4)= 5 么?
代码:PrivateSubCommand1_Click()Dima(6)AsIntegerDimxAsInteger,iAsIntegerPrintf(2)Fori=1T...
代码:
Private Sub Command1_Click()
Dim a(6) As Integer
Dim x As Integer, i As Integer
Print f(2)
For i = 1 To 5
a(i) = f(i)
Next i
Print a(1)
Print a(4)
End Sub
Function f(x As Integer)
x = x + 1
f = x
End Function 展开
Private Sub Command1_Click()
Dim a(6) As Integer
Dim x As Integer, i As Integer
Print f(2)
For i = 1 To 5
a(i) = f(i)
Next i
Print a(1)
Print a(4)
End Sub
Function f(x As Integer)
x = x + 1
f = x
End Function 展开
1个回答
2015-01-06
展开全部
Private Sub Command1_Click()
Dim a(6) As Integer
Dim x As Integer, i As Integer
Print f(2)
For i = 1 To 5
Debug.Print i, '增加这两句,在立即窗口中看打印内容就知道了
a(i) = f(i)
Debug.Print a(i), i '增加这两句,在立即窗口中看打印内容就知道了
Next i
Print a(1)
Print a(4)
End Sub
Function f(x As Integer)
x = x + 1
f = x
End Function
'立即窗口打印结果:
' 1 2 2 i=1时,经过f函数,变为2,未给a(1)赋值,所以为0
' 3 4 4
' 5 6 6
Dim a(6) As Integer
Dim x As Integer, i As Integer
Print f(2)
For i = 1 To 5
Debug.Print i, '增加这两句,在立即窗口中看打印内容就知道了
a(i) = f(i)
Debug.Print a(i), i '增加这两句,在立即窗口中看打印内容就知道了
Next i
Print a(1)
Print a(4)
End Sub
Function f(x As Integer)
x = x + 1
f = x
End Function
'立即窗口打印结果:
' 1 2 2 i=1时,经过f函数,变为2,未给a(1)赋值,所以为0
' 3 4 4
' 5 6 6
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询