扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
Option Explicit
公司主营业务:网站设计、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出天峻免费做网站回馈大家。
Function JionNumber(a As Variant, b As Variant, c As Variant) 'a数组和b数组 合并到c数组
Dim i As Integer, j As Integer
ReDim c(UBound(a) + UBound(b) + 1)
For i = 0 To UBound(a)
c(i) = a(i)
Next
For j = i To UBound(b) + i
c(j) = b(j - i)
Next
End Function
Private Sub SelectSort(Xarray() As Variant) '选择排序法,升序排序
Dim i%, j%, k%, t%, Start%, Finish%
Start = LBound(Xarray, 1)
Finish = UBound(Xarray, 1)
For i = Start To Finish - 1
k = i
For j = i + 1 To Finish
If Xarray(j) Xarray(k) Then k = j 'k表示当前最大值对应的下标
Next j
If k i Then
t = Xarray(i)
Xarray(i) = Xarray(k)
Xarray(k) = t
End If
Next i
End Sub
Private Sub Command1_Click()
Dim a() As Variant, b() As Variant, c() As Variant, d() As Variant, e() As Variant
Dim f() As Variant '合并后的数组
Dim ab, abc, abcd, i%
a = Array(10, 11, 18, 19, 26, 27, 40, 41, 48, 49)
b = Array(1, 8, 9, 22, 23, 30, 31, 38, 39)
c = Array(6, 7, 14, 15, 28, 29, 36, 37, 44, 45)
d = Array(2, 3, 16, 17, 24, 25, 32, 33, 46, 47)
e = Array(4, 5, 12, 13, 20, 21, 34, 35, 42, 43)
JionNumber a, b, ab '合并数组
JionNumber ab, c, abc
JionNumber abc, d, abcd
JionNumber abcd, e, f
Text1 = "排序前:" vbCrLf
For i = 0 To UBound(f)
Text1 = Text1 " " f(i)
Next i
Text1 = Text1 vbCrLf "排序后:" vbCrLf
SelectSort f() '排序
For i = 0 To UBound(f)
Text1 = Text1 " " f(i)
Next i
End Sub
Text1属性:MultiLine 设为 True,ScrollBars设为2
合并数组没有简单办法,只能一维一维的取出来,放到一新数组中。新数组维数是原两数组维数相加。
比如两个数组 A ,B
dim newAr() '如果两个数组类型相同话 ,可以定义类型。
redim newAr(ubound(A)-lbound(A)+1+ubound(B)-lbound(B)+1-1) ‘由于数组定义只能用常数表达式定义维数,所以用动态数组。
把两数组项目添加到newAr 中
dim Index as integer
dim i as integer
for i=LBound(A) to UBound(A)
newAr(Index)=A(i)
Index=Index+1
next
for i=LBound(B) to UBound(B)
newAr(Index)=B(i)
Index=Index+1
next
Private Sub Command1_Click()
a = Array(1, 2, 4, 7, 9, 34, 65, 73, 78, 99, 234, 1234)
b = Array(0, 23, 33, 56, 78, 98, 99, 234, 1000, 9999)
Dim c(30)
i = 0
j = 0
k = 0
While i = UBound(a) And 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
Wend
While i UBound(a)
c(k) = a(i)
i = i + 1: k = k + 1
Wend
While j UBound(b)
c(k) = b(j)
j = j + 1: k = k + 1
Wend
Print "原A数组:"
For i = 0 To UBound(a)
Print a(i);
Next i
Print "原B数组:"
For i = 0 To UBound(b)
Print b(i);
Next i
Print "合并后的c数组:"
For i = 0 To k
Print c(i);
If i Mod 15 = 14 Then Print
Next i
End Sub
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流