ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

°}¦Cª«¥óArrayList »P°}¦CArray²V·f °ÝÃD

°}¦Cª«¥óArrayList »P°}¦CArray²V·f °ÝÃD

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-2-11 02:12 ½s¿è



Sub ttttt()
Set arL = CreateObject("System.Collections.ArrayList")
Dim br(4)
For i = 1 To 2
arL.Add br
Next
arL(1)(0) = 4
arL.Add 3
arL.Add Array("red", "white", "green")
Debug.Print arL(1)(0)
End Sub

¦p¹Ï¶×¤J«á §ä¤£¨ì¸ê®Æ

½Ð°Ý
¦p¦ó±N¸ê®Æ¨Ì  ¦C¸¹ or ¦WºÙ ¥¿½T¶×¤J?
¦p¦ó±N³æ¤@¸ê®Æ¨Ì  ¦C¸¹ or ¦WºÙ ¥¿½T ´£¨ú?

¥t¥~§Ú¦bºô¸ô¤W§ä¨ì¤@­Ó«Ü¯S®íªº¥Îªk
Sub ReadRangeExample()
Dim MyList1 As Object
Set MyList = CreateObject("System.Collections.ArrayList")
'Dim MyList As New ArrayList, MyList1 As Object
MyList.Add "Item1"
MyList.Add "Item2"
MyList.Add "Item3"
MyList.Add "Item6"
MyList.Add "Item4"
MyList.Add "Item7"
Set MyList1 = MyList.GetRange(2, 4)
For Each I In MyList1
    MsgBox I
Next I
End Sub

¹Á¸Õ Æ[¹îºÊ¬Ý¦¡  µo²{  ª«¥ó¤£¬O®ø¥¢ ¦Ó¬O·|³Q¼È®É½ü¬yÃö³¬

¦^´_ 1# singo1232001

¦Û°Ý¦Ûµª §ä¨ìµª®×¤F


¨Ó·½https://www.snb-vba.eu/VBA_Arraylist_en.html

TOP

¦^´_ 2# singo1232001

Ä~Äò°l¥[°ÝÃD¤@¤U
ºÊ¬Ý¾¹¤Þ¥Î ¥~³¡ª«¥ó ±`±`²§±`
    ´£°Ý  ³o¬Obug¶Ü?
¦]¬°¤£¦n¤å¦r±Ô­z ÁÙ¬O½Ð¬Ý¼v¤ù¤ñ¸û§Ö
¥D­n¬OºÊ¬Ý¦¡ª«¥ó¥Ã»·¥X²{·N·Q¤£¨ìªº²{¶H
https://www.youtube.com/watch?v=MlxAzvK0jrk

TOP

¦^´_  singo1232001

¦Û°Ý¦Ûµª §ä¨ìµª®×¤F
singo1232001 µoªí©ó 2022-2-11 02:35



§A½T©w¦³§ä¨ìµª®×?
2ºûªºÁÙ¬OµLªk­×§ï­È§r

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-2-12 03:10 ½s¿è

¦^´_ 4# jackyq


    ¦³§ä¨ì¤@¨Çµïµ·°¨¸ñ

1.¨Ï¥Îarraylist®É ºÊ¬Ý¦¡®e©ö²§±` ¤£¯à¤Ó¹L¬Û«H ¦]¬°¬O¤Þ¥Î¥~³¡(.Net framework)ªºDLL «DVBA¦Û±a (¤W­±§Ú¦³¶Ç¼v¤ù)
2.¥u­n¦Aarraylist°}¦C¤§«á ©ÎªÌ³QarrayList¥]¦í  ©³¤U´N¨S¦³vba°}¦C  ©³¤Uªºvba°}¦C·|³Q¦Û°Ê§ï¦¨arraylist°}¦C
3.¦p¤W­z  ¦Ó¦barraylist°}¦C¤§«eªºVBA°}¦C ¤£¨ü¼vÅT ¤]´N¬O VBA°}¦C¯à¥]¦íarraylist°}¦C  ¦ýarraylist°}¦C¤£¯à¥]vba°}¦C ¹ê»Ú¾Þ§@®É³Qarraylist¥]¦íªºvba°}¦C·|³Q±j¨î§ï¦¨arraylist°}¦C
4.ºÊ¬Ý¬d¸ßarraylist®É ¥i¥H¥Îar.item(0) ©ÎªÌar(0)ªº¤è¦¡¬d¸ß ¤]¥i¥H¿é¤J ¦ý«e´£¬O¦³add¤@­Ó¦ì¸m
5.ªÅ¥ÕªºarraylistµLªk¹³dctionary(¦r¨å)ª½±µ³sÄò´O®Marraylist ­Y­n´O®M ¥²¶·¦b´O®M«e ·s¼W ar.add "" ¤@­Ó¦û¦ì¥Îªº¦ì¸m ¤~¥i¥H§Q¥Î³o­Ó¦ì¸m¨Ó­«·s Set ar(0) = CreateObject("System.Collections.ArrayList")
6.¦p¤W­z «Ü³Â·Ð«ç»ò¿ì,³o®É­Ô¥i¥H§Q¥Î²Ä2ÂIªº³W«h  ¥ý³Ð¤@­Ó§A·Q­nªºvbaªºNºû°}¦C
¤ñ¦p
Dim br(3, 3, 3) ©ÎªÌ redim br(3, 3, 3)
Set ar= CreateObject("System.Collections.ArrayList")
ar.Add ""
ar.Add br
´N¥i¥Hª½±µ³Ð³y§A·Q­nªº´O®M°}¦C
»P¦r¨å¤£¦Pªº±¡ªp¬O ¦r¨å¦L¶H¤¤¤£·|§âvba°}¦CÅܦ¨arraylist°}¦C
(¦ý³oºØ¤è¦¡ ¤£ºÞ«ç»ò¹Á¸Õ³Ì«á¦n¹³¥¢±Ñ¤F ÁöµM°}¦C¬[ºc¤]¦³¥X²{. ¦Ó¥B¤]¯à¥¿½T°õ¦æ¶×¤J¸ê®Æ,¦ý§¹¥þ¨SÅã¥Ü¥ô¦ó¸ê®Æ¶×¤J ¸ê®Æ·|ª½±µ¶i¤JµêªÅ¤§¤¤ ´Nºâdebug.print¥X¨Ó¤]¬O"ªÅ®ð" )

Sub Array_Arraylist2()
Dim ar(1)
Dim br(2, 2)
Set ar(0) = CreateObject("System.Collections.ArrayList")
ar(0).Add br
ar(0).Add ""

ar(0)(0)(0, 0) = 555
ar(0)(0)(0, 1) = 666
ar(0)(0)(0, 2) = 777

Debug.Print ar(0)(0)(0, 0)
Debug.Print ar(0)(0)(0, 1)
Debug.Print ar(0)(0)(0, 2)

End Sub





7.®i¥Ü¤@­Ó vba°}¦C ¥] arraylist°}¦C ¨Ã½á­È¨ú­Èªº¤èªk (¬°¤F³v¨B®i¥Ü ©Ò¥H¤£¥Î6ªº¤èªk)

Sub Array_Arraylist()
Dim ar(1)
Set ar(0) = CreateObject("System.Collections.ArrayList")
ar(0).Add ""
ar(0).Add ""
ar(0).Add Array(11, 12, 13, 14)
Set ar(0)(0) = CreateObject("System.Collections.ArrayList")
ar(0)(0).Add ""
ar(0)(0).Add ""
ar(0)(0).Add ""
ar(0)(0).Add ""
ar(0)(0)(0) = 331
ar(0)(0)(1) = 332
ar(0)(0)(2) = 333
ar(0)(0)(3) = 334
Debug.Print ar(0)(0)(0)
Debug.Print ar(0)(0)(1)
Debug.Print ar(0)(0)(2)
Debug.Print ar(0)(0)(3)
End Sub

¬ã¨s¨ì³Ì«á

­Y¥u¥Îarraylist ´N¥i¥Hª½±µ¶×¤J­×§ï
¦ý¦pªG¥Îarraylist ¥]vba°}¦C
¥u¦³¨â­Ó¤èªk¯à³B²z ­×§ï
­º¥ýÁקK¥Îarraylist¥]vba°}¦Cªº§Î¦¡  ¦ývba°}¦C¥i¥H¥]arraylist

¦ý´N·Qª½±µarraylist¥]°}¦C«ç»ò¿ì  ¥]¬A«á­±¥Î .Add Array(1,2,3,4) ³oºØ1ºû°}¦C¤]ºâ
²Ä¤@  ¨Ï¥Îadd+removeat ©Îremoveªº¤è¦¡­×§ï
²Ä¤G  ¶×¤Jvba°}¦C®É ¸ê®Æ´N­n¥ý¿é¤J¦n¤F ¿é¤J¦n¤§«á´N¤£¯à¦A§ï

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-2-12 03:23 ½s¿è


Sub Array_Arraylist3()
Dim ar(1)
Dim br(2, 2)
Set ar(0) = CreateObject("System.Collections.ArrayList")
ar(0).Add br
ar(0).Add ""
ar(0).Add Array(1, 2, 3, 4)
ar(0)(0)(0, 0) = 555
ar(0)(0)(0, 1) = 666
ar(0)(0)(0, 2) = 777

Debug.Print ar(0)(0)(0, 0) & "ªÅ¥Õ"
Debug.Print ar(0)(0)(0, 1) & "ªÅ¥Õ"
Debug.Print ar(0)(0)(0, 2) & "ªÅ¥Õ"
Debug.Print ar(0)(2)(0)
Debug.Print ar(0)(2)(1)
Debug.Print ar(0)(2)(2)
Debug.Print ar(0)(2)(3)
End Sub

¤W­z§Ú¨Ï¥Î¤F¨âºØ¤£¦Pªºarraylist¥]vba°}¦C¶×¤J¤è¦¡  
¤@ºØ¬OªÅ¥Õvba°}¦Cbr(2,2)
¤@ºØ¬O­ì¥»´N¦³¸ê®Æªºvba°}¦C  array(1,2,3,4)
³Ì«á¦³¸ê®Æªº¬O²Ä¤GºØ
ÁöµM²Ä¤@ºØ¤]¯à°õ¦æ ¦ý¸ê®Æ¶i¤£¥h

ª`·N ¦¹®×¨Ò»P¤W¤@½g¦^´_ªº¤£¦P
¤W¤@½g¬O¨Ï¥Î¥¿³Wªºarraylist´O®M¤èªk
©Ò¥Har(0)(0)(0) = 331 ¦³¶×¤J¦¨¥\
¦Ó¥»½gªº
ar(0)(0)(0, 0) = 555 ¶×¤J¥¢±Ñ

½Ð°ª¤â¸Ô¸Ñ¤@¤U  ·PÁ ¬ÛÃö¸ê®Æ¹ê¦b§ä¤£¤Ó¨ì

TOP

¦^´_ 6# singo1232001


¬Ý³o­Ó·|§ó¥[ª½Æ[

Sub Array_Arraylist4()
Dim ar(0): Dim br(2): Dim cr(2)
cr(0) = "97": cr(1) = "98": cr(2) = "99":
Set ar(0) = CreateObject("System.Collections.ArrayList")
ar(0).Add br
ar(0).Add Array(1, 2, 3)
ar(0).Add cr
ar(0)(0)(0) = 555
ar(0)(0)(1) = 666
ar(0)(0)(2) = 777
Debug.Print ar(0)(0)(0) & " brªÅ¥Õ"
Debug.Print ar(0)(0)(1) & " brªÅ¥Õ"
Debug.Print ar(0)(0)(2) & " brªÅ¥Õ"
Debug.Print ar(0)(1)(0) & " Array(1, 2, 3, 4)¦³ªF¦è"
Debug.Print ar(0)(1)(1) & " Array(1, 2, 3, 4)¦³ªF¦è"
Debug.Print ar(0)(1)(2) & " Array(1, 2, 3, 4)¦³ªF¦è"
Debug.Print ar(0)(2)(0) & " cr¦³ªF¦è"
Debug.Print ar(0)(2)(1) & " cr¦³ªF¦è"
Debug.Print ar(0)(2)(2) & " cr¦³ªF¦è"
'----¥H¤U¬O¦barraylist«á ·s¼W¤@­Ó¥¿±`ªºarraylist ¨Ã¥B¥i¥H½á­È¨ú­È
ar(0).Add ""
Set ar(0)(3) = CreateObject("System.Collections.ArrayList")
ar(0)(3).Add ""
Set ar(0)(3)(0) = CreateObject("System.Collections.ArrayList")
ar(0)(3)(0).Add "¥¿±`ªºarraylist·s¼W"
Debug.Print ar(0)(3)(0)(0)
ar(0)(3)(0)(0) = "¥¿±`ªºarraylist­×§ï«á"
Debug.Print ar(0)(3)(0)(0)
End Sub


³o´N¬Oarraylist ³o­Ó§|«ÜÁV¿|ªº­ì¦]
   
¦ý¦b¬Y¨Ç¸ê®Æ¶q«Ü¤j¤S­n°Ï¤Àªº±¡ªp¤U ¤S¤£±o¤£¥Î¥L

TOP

        ÀR«ä¦Û¦b : °µ¸Ó°µªº¨Æ¬O´¼¼z¡A°µ¤£¸Ó°µªº¨Æ¬O·Mè¡C
ªð¦^¦Cªí ¤W¤@¥DÃD