VB之数组

1.动态数组 一直给每一个数组赋值,直到空的停止,最多a(0.1.2)

2.排序

Dim a(9) As Long
Private Sub Command1_Click()
Dim i As Long, j As Long, b As Long
For i = 1 To 9
For j = 0 To 9 - i
'Debug.Print i
If a(j) < a(j + 1) Then
b = a(j)
Debug.Print j
a(j) = a(j + 1)
a(j + 1) = b
End If
Next j
Next i
For i = 0 To 9
Text1.Text = Text1.Text + CStr(a(i)) + " "
If i = 4 Then Text1.Text = Text1.Text + Chr(13) + Chr(10)
Next i
End Sub
Private Sub Command2_Click()
Dim i As Long, l
Text1.Text = ""
For i = 0 To 9
n:
l = InputBox("请输入排序的10个数字,这是第" & CStr(i + 1) & "个", "")
If IsNumeric(i) Then
49
a(i) = l
Else
MsgBox "请输入数字", vbOKOnly, "错误"
GoTo n
End If
Next i
End Sub