插入时,重定义数组,每次加一个。从数组尾部开始循环往后移动一个位置,并比较,当插入值小于比较的那个值时停止。并在那个位置插入。
给你一个比较无脑的例子,先插入text1 text2 command1
text1插入,text2显示,command1插入的命令按钮
Dim a As Variant
Dim b()
Private Sub Command1_Click()
n = UBound(a)
ReDim b(n + 1)
For i = 0 To n
b(i) = a(i)
Next
Do While end1 <> 1
If b(n) >= Val(Text1.Text) Then b(n + 1) = b(n)
If b(n) <= Val(Text1.Text) Then end1 = 1: b(n + 1) = Val(Text1.Text)
n = n - 1
Loop
Text2.Text = ""
For i = 0 To UBound(b)
Text2.Text = Text2.Text & " " & b(i)
Next
a = b
End Sub
Private Sub Form_Load()
a = Array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19)
Text2.Text = "1, 3, 5, 7, 9, 11, 13, 15, 17, 19"
End Sub