Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x(), y(), i, z As Integer ReDim x(4), y(4) For i = 1 To 5 x(i - 1) = i Next test1(z, x, y) TextBox1.Text += y(0) & vbTab & y(1) & vbTab & y(2) & vbTab & y(3) & vbTab & y(4) & vbCrLf TextBox1.Text = TextBox1.Text & z End Sub Sub test1(ByVal z As Integer, ByVal xx() As Integer, ByVal yy() As Integer) Dim i As Integer For i = 0 To 4 yy(i) = xx(i) + xx(i) z += xx(i) Next End Sub
[解决办法] [code=VB.NET][/code] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x(), y(), i, z As Integer ReDim x(4), y(4) For i = 1 To 5 x(i - 1) = i Next test1(z, x, y) TextBox1.Text += y(0) & vbTab & y(1) & vbTab & y(2) & vbTab & y(3) & vbTab & y(4) & vbCrLf TextBox1.Text = TextBox1.Text & z End Sub
Sub test1(ByRef z As Integer, ByVal xx() As Integer, ByVal yy() As Integer) Dim i As Integer For i = 0 To 4 yy(i) = xx(i) + xx(i) z += xx(i) Next End Sub 这是值传递和址传递。你那个局部变量是值传递,数组是址传递! [解决办法] vb6也有这个问题的,只是参数的默认方式改变了,以前默认是byref,现在默认是byval了 [解决办法]