標題:
如何把兩個Array合併?
[打印本頁]
作者:
FAlonso
時間:
2011-3-29 21:34
標題:
如何把兩個Array合併?
除了這個麻煩辦法外
Sub abc()
Dim a(), b(), c(), i
a = Array("Tony", "Garnett")
b = Array("Allen", "Pierce", "Bryant")
ReDim Preserve c(UBound(a) + UBound(b) + 1)
For i = 0 To UBound(a)
c(i) = a(i)
Next
For i = 0 To UBound(b)
c(i + UBound(a) + 1) = b(i)
Next
End Sub
複製代碼
有沒有快捷方法處理?
作者:
GBKEE
時間:
2011-3-29 21:45
回復
1#
FAlonso
適用一維陣列
Sub ex()
Dim a(), b(), C As Variant
a = Array("Tony", "Garnett")
b = Array("Allen", "Pierce", "Bryant")
C = Join(a, ",") & "," & Join(b, ",")
C = Split(C, ",")
MsgBox Join(C, ",")
End Sub
複製代碼
作者:
FAlonso
時間:
2011-3-29 22:21
回復
2#
GBKEE
Sub combine_array_GBKEE()
Dim a(), b(), c As Variant, d(), i As Integer, j As Integer
a = Array("Tony", "Garnett")
b = Array("Allen", "Pierce", "Bryant")
c = Join(a, ",") & "," & Join(b, ",")
i = UBound(Split(c, ","))
ReDim Preserve d(i)
For j = 0 To i
d(j) = Split(c, ",")(j)
Next
End Sub
複製代碼
已經略作修改,完成了
多謝各位指導
作者:
GBKEE
時間:
2011-3-30 06:35
回復
4#
chin15
你的發文下方 [編輯],
勾選右上 [刪] ,[編輯帖子]
刪除完畢
作者:
chin15
時間:
2011-3-30 08:30
謝謝指教,我會了
已成功刪除自己造成的垃圾
作者:
GBKEE
時間:
2011-3-30 11:48
回復
3#
FAlonso
Sub Ex()
Dim A(0 To 3), C(), E, R
A(0) = Array("Tony", "Garnett")
A(1) = Array("Allen", "Pierce", "Bryant")
A(2) = Array("A1", "B1", "C1")
A(3) = Array("AA1", "BB1", "CC1")
ReDim C(0)
For Each E In A
For Each R In E
C(UBound(C)) = R
ReDim Preserve C(UBound(C) + 1)
Next
Next
ReDim Preserve C(UBound(C) - 1)
MsgBox Join(C, ",")
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)