VB问题,各位大神麻烦了~~~
将两个有序数且A和B合并成另一个有序的数组C。(不懂为什么老是提示下界越界。。。主要是不知道那个C的界限怎么定。。。)OptionBase1Dima()AsVariant...
将两个有序数且A和B合并成另一个有序的数组C 。(不懂为什么老是提示下界越界。。。主要是不知道那个C的界限怎么定。。。)
Option Base 1
Dim a() As Variant, b() As Variant, c() As Variant, v As Variant
Private Sub Form_Click()
a = Array(1, 3, 5, 7, 9, 11, 15, 20, 25, 30)
b = Array(2, 4, 6, 8, 10, 12)
Dim i%, j%, k%
i = 1: j = 1: k = 1
Do While a(i) <= UBound(a) And b(j) <= UBound(b)
If a(i) < b(j) Then
c(k) = a(i)
i = i + 1
Else
c(k) = b(j)
j = j + 1
End If
k = k + 1
Loop
Do While a(i) <= UBound(a)
c(k) = a(i)
i = i + 1
Loop
Do While b(j) <= UBound(b)
c(k) = b(j)
j = j + 1
Loop
For Each v In c()
Print v;
Next
End Sub 展开
Option Base 1
Dim a() As Variant, b() As Variant, c() As Variant, v As Variant
Private Sub Form_Click()
a = Array(1, 3, 5, 7, 9, 11, 15, 20, 25, 30)
b = Array(2, 4, 6, 8, 10, 12)
Dim i%, j%, k%
i = 1: j = 1: k = 1
Do While a(i) <= UBound(a) And b(j) <= UBound(b)
If a(i) < b(j) Then
c(k) = a(i)
i = i + 1
Else
c(k) = b(j)
j = j + 1
End If
k = k + 1
Loop
Do While a(i) <= UBound(a)
c(k) = a(i)
i = i + 1
Loop
Do While b(j) <= UBound(b)
c(k) = b(j)
j = j + 1
Loop
For Each v In c()
Print v;
Next
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询