VB编程,帮我看看哪错了
来源:百度知道 编辑:UC知道 时间:2024/08/22 09:44:19
Private Sub Command1_Click()
Dim a(20) As Integer
Dim i As Integer, m As Integer
For i = 1 To 20
a(i) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & a(i) & " "
Next i
For i = 1 To 20
m = a(i)
a(i) = a(21 - i)
a(21 - i) = m
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
试试这个。
Private Sub Command1_Click()
Dim a(20) As Integer
Dim I As Integer, m As Integer
For I = 1 To 20
a(I) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & a(I) & " "
Next
For I = 1 To 10'不是20
m = a(I)
a(I) = a(21 - I)
a(21 - I) = m
Next
For I = 1 To 20'输出
Text2.Text = Text2.Text & a(I) & " "
Next
End Sub
修改了几处。
注意:数组的第一个下标是0;
a(20)中的元素值是从a(0)、a(1)、a(2)……a(19)。根本没有a(20)这个元素!!
..........黑龙江省巴彦县兴隆镇中心校 张志晨老师.............
............以诚待友.........守信做人.......................
Private Sub Command1_Click()
Dim a(20) As Integer
Dim i As Integer, m As Integer
For i = 0 To 19
a(i) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & a(i) & " "
Next i
For i = 0 To 9
m = a(i)
a(i) = a(19 - i)
a(19 - i) = m
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
改成下面的就可以了,实