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

[µo°Ý] ¦p¦ó¤~¯à¥Î¦CÁ|¤è¦¡¨Ó«ü©w¾ã¼Æ°}¦Cªº¤º®e­È

[µo°Ý] ¦p¦ó¤~¯à¥Î¦CÁ|¤è¦¡¨Ó«ü©w¾ã¼Æ°}¦Cªº¤º®e­È

¥»©«³Ì«á¥Ñ luhpro ©ó 2011-4-30 05:24 ½s¿è

·Q½Ð°Ý©³¤Uµ{¦¡¤¤ªº°}¦C¬°¦ó¤£¯à«ü©w©O?
Dim A(0 To 2) As Integer
A = Array(10, 20, 30)

­Y§ï¥Î³o¼Ë´N¥i¥H :
(¨ú¦Û Excel »¡©ú¤¤ªº½d¨Ò)
Dim A As Variant
A = Array(10, 20, 30)

©Î

(¥H¤U¬°§Ú¥Ø«e¥Îªº¤è¦¡, ¤]¬O ¨ú¦ÛExcel »¡©ú¤¤ªº½d¨Ò, ¥Î°_¨Ó«Ü¤£¤è«K)
Dim A%(0 To 2)
A(0) = 10
A(1) = 20
A(0) = 30

Ãø¹D¤£¯à¥Î¦CÁ|ªº¤è¦¡¤@¦¸«ü©w¾ã­Ó¾ã¼Æ°}¦Cªº­È¶Ü?

Ãø¹D¤£¯à¥Î¦CÁ|ªº¤è¦¡¤@¦¸«ü©w¾ã­Ó¾ã¼Æ°}¦Cªº­È¶Ü?
¤]³\§A¸Ó¸ÑÄÀ¤@¤U¤°»ò¬O¥Î¦CÁ|ªº¤è¦¡

TOP

¦^´_ 2# chin15

©êºp, ¥i¯à¬O§Ú»¡ªº¤£²M·¡,
©Ò¿×¦CÁ|¦¡ªº¤è¦¡´N¬O¾ã­Ó°}¦Cªº­È¥i¥H¤@¦¸´N¥þ³¡«ü©w.
Á|¨Ò¨Ó»¡:
A(0) = 5
A(1) = 53
A(2) = 52
A(3) = 57
A(4) = 43
A(5) = 0
.
.
.
§ÚºÙ¬°³v­Óµ¹­È, ¦pªG¾ã­Ó°}¦C¦³ 100 ­Ó¶Ã¼Æ­È, ´N­n¥´ 100 ¦æµ¹­Èªº«ü¥O, ¦Ó¥B A(x) ¤¤ªº x ÁÙ¤£¯à¥´¿ù

¦Ó©³¤U³o­Ó
A = Array(5,53,52,57,43,0,52,72,93,12)

§ÚºÙ¬°¦CÁ|¦¡µ¹­È.

TOP

³o¬Oª½±µ½á­È¡A§A«e­±¤£¬O¤w¸g¥i¥H¤F¶Ü¡H

TOP

¦^´_ 1# luhpro
Ãø¹D¤£¯à¥Î¦CÁ|ªº¤è¦¡¤@¦¸«ü©w¾ã­Ó¾ã¼Æ°}¦Cªº­È¶Ü?
  1. Sub Ex()
  2.     Dim A
  3.     A = Array(10, 20, 30)
  4.     MsgBox A(0)
  5.     A(0) = 50
  6.     MsgBox A(0)
  7. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ luhpro ©ó 2011-4-30 22:00 ½s¿è

¦^´_ 5# GBKEE
¦^´_ 4# chin15

«e­±´N¬O¤£¦æ°Ú,
¨ººØ¤è¦¡¥u¯à¥Î¦b Variant «¬ºA,
¦ý Integer «¬ºA Excel ¤£Åý¥Î,
¥u¯à¥Î "³v­Óµ¹­È" (¦p¤W­z). ><

TOP

³o¼Ëªº°}¦C¡A¤£ºÞ¤¸¯À¬O¦óÃþ«¬
¹ï°}¦C¥»¨­¨Ó»¡³£¬OVariant «¬ºAªº
¹B¦æ³o¤@¬q
A = Array(10, 20, 30)
MsgBox TypeName(A)
´Nª¾¹DÀ³¸Ó©w¸q¬°¦óºØÃþ«¬

TOP

  1. Sub nn()
  2. Dim ar(0 To 10) As Integer, ay(0 To 3) As String, y
  3. y = Array(1, "L", 2, "K") '°}¦C¤¤ªº¸ê®Æ¥i¥H¬O¤£¦P«¬ºA¸ê®Æ
  4. MsgBox Join(y, Chr(10))
  5. For i = 0 To 10
  6. ar(i) = i
  7. Next
  8. For i = 0 To 3
  9. ay(i) = i
  10. Next
  11. a = Array(ar, ay)
  12. MsgBox TypeName(a) 'Åã¥ÜÅܼÆaªº¸ê®Æ«¬ºA
  13. For Each c In a
  14.    If TypeName(c) = "String()" Then MsgBox Join(c, Chr(10)) '¦pªG¬O¦r¦ê¤@ºû°}¦C´NÅã¥Ü¤º®e
  15.    If TypeName(c) = "Integer()" Then MsgBox Application.Sum(c) '¦pªG¬O¾ã¼Æ¤@ºû°}¦C´NÅã¥Ü¥[Á`µ²ªG
  16. Next
  17. End Sub
½Æ»s¥N½X
Array¬O¨ç¼Æ¡A¨ä¤¤ªº¤¸¯À´Nµ¥¦P¨ç¼Æªº¤Þ¼Æ¡A©Ò¥H¥¦¬O¶Ç¦^¤@­Ó°}¦C«¬ºAªºÅܼÆ,¥L¬OVariant «¬ºA
³o­ÓVariant «¬ºAªº¤¸¯À¬O¥i¥H¬°¥ô¦ó«¬ºA(¥]§t°}¦C)ªº¤¸¯À
¥ÎArray¨ç¼Æ«Ø¥ßªº°}¦C¡A¶Ç¦^ªº­È¡A¨ä«¬ºA´N¬OVariant
³o´N¬OVBA»¡©ú¤¤©Ò»¡:Variant Åܼƥi¥H§t¦³¥ô¦ó«¬ºAªº°}¦C¡A°£¤F©T©wªø«×¦r¦ê©M ¨Ï¥ÎªÌ¦Û­q«¬ºA¥H¥~

¥HDim«Å§iªº°}¦C¬O¥¬¸m¤@­Ó°}¦CªÅ¶¡¡A¦Ó¤£¬Oª½±µ½á­È¡A©Ò¥H¥²¶·°w¹ï¨C­ÓªÅ¶¡¤@¤@µ¹­È
·í§A¦bDIM«Å§i®É¨S¦³«ü©w°}¦C¤j¤p®É¡A¸Ó°}¦C´N¬O°ÊºA°}¦C
©Ò¥H¥²¶·¨Ï¥ÎREDIM¨Ó­«·s©w¸qªÅ¶¡¤j¤p¡A¤~¯à¦A±N¤¸¯À¼g¤J¸Ó°}¦C

§Ú´¿¥Î¤@­Ó¤ñ³ë
Array¨ç¼Æ¡A´N¬O¤@¸J²±¦nªF¦èªº¸J¡A¸Ì­±ªºªF¦è¬O¥i¥H¸Ë¤J¤£¦Pªºª««~
Dim«Å§iªºÅܼƥL¬O¤@­ÓªÅªº¸J¡A¦pªG¨S¦³«Å§i«¬ºA®É¡A¥L¬O¥i¥H¸Ë¥ô¦ó¤£¦Pª««~ªºªÅ¸J¡A¤£¹L¦b«Å§i®É¨Ã¨S¦³¸Ëª««~
©Ò¥H­n¸Ëª««~®É¡A­n¥ý·Ç³Æ¦n¼Æ¶q¨¬°÷ªºªÅ¸J¤~¯à±N¤@°ïª««~¦³³W«hªº©ñ¶i¸J¸Ì
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2011-5-1 06:26 ½s¿è

¦^´_ 6# luhpro
[µLªk«ü©w¦Ü°}¦C] VBAªº»¡©ú
°}¦C¤¤ªº¦U¤¸¯À¡A¥²¶·­Ó§O«ü©w¨ä­È¡C³o­Ó¿ù»~ªº°_¦]»P¸Ñ¨M¤èªk¦p¤U©Ò¥Ü¡G
±z¸Õ¹Ï±N¤@­Ó­È«ü©wµ¹¤@­Ó°}¦CÅܼơA¦ý¨S¦³«ü©w­n±N³o­Ó­È«ü©wµ¹­þ­Ó¤¸¯À¡C
­n³]©w¤@­Ó°}¦C¤¤ªº¤¸¯À¡A±z´N¥²¶·«ü©w¦¹¤¸¯Àªºµù¼Ð¡C¨Ò¦p¡A­Y MyArray ¬°¤@­Ó¾ã¼Æ°}¦C¡A«h¹Bºâ¦¡ MyArray = 5 ¬O¤£¥¿½Tªº¡A¤U¦Cªº¹Bºâ¦¡¤~¬O¥¿½Tªº¡G
MyArray(UBound(MyArray)) = 5
  1. Sub ¥i¦æ()
  2.     Dim A()
  3.     A = Array(1, 2)
  4.     ReDim Preserve A(UBound(A) + 1)
  5.     A(UBound(A)) = 10
  6.     MsgBox UBound(A)
  7. End Sub
  8. '''''''''''''''''''''''''''''''''''''''''''''
  9. Sub ¤£¥i¦æ()
  10. Dim A(1)
  11. A = Array(1,2)
  12. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ luhpro ©ó 2011-5-1 07:45 ½s¿è

¦^´_ 7# chin15
ÁÂÁÂ chin15

¦]¬°¥H«e¥Î¹L Turbo C ³]©w¾ã¼Æ°}¦Cªº¤è¦¡¥i¥H¬O
int *A[] = { 5, 53, 52, 57, 43, 0, 52, 72, 93, 12};
³o¼Ëªº¤è¦¡¨Ó³]©w¾ã¼Æ°}¦C,
©Ò¥H¤~·|·Q VBA ¬O§_¤]¦³Ãþ¦üªº¤èªk¥i¥H¥Î¦CÁ|¦¡¹ï¾ã¼Æ°}¦Cµ¹­È.

¦^´_ 9# GBKEE
ÁÂÁÂ GBKEE
²³æªº»¡¥Î Variant ¼u©Ê«Ü¤j,
¦Ó¬Y¨ÇÅܼƤ@¦ý©w¸q¤U¥h,
·Q­nÅܧ󤺮e¥i¯à«ü¥O´N­n¤£¤@¼Ë¤F.

¦^´_ 8# Hsieh
ÁÂÁÂ Hsieh
¦]¬°µ{¦¡Àô¹Ò»Ý¨D¤W»Ý­n¹ï°O¾ÐÅéªÅ¶¡¤ç¤ç­p¸û,
©Ò¥H¤~·|§Æ±æ¸Ó°}¦C¯à¤£­n¥Î Variant «¬ºA(¤Ó¦ûªÅ¶¡¤F),
¥J²Ó«ä¦Ò¤F¤@¤U§Ú¥´ºâ±Ä¥Î¤U¦Cªº¤è¦¡ :
Dim iAr%(0 To 99), iI%
Dim vA

vA = Array(5, 53, 52, 57, 43, 0, 52, 72, 93, 12, _
    26, 40, 84, 45, 59, 45, 91, 5, 97, 21, _
    14, 47, 59, 61, 91, 5, 73, 94, 41, 33, _
    5, 55, 80, 95, 54, 89, 29, 65, 13, 51, _
    54, 78, 35, 86, 49, 48, 95, 25, 10, 76, _
    96, 59, 47, 11, 59, 50, 73, 26, 2, 26, _
    76, 39, 46, 74, 8, 56, 23, 8, 29, 1, _
    86, 54, 42, 81, 59, 80, 9, 28, 54, 7, _
    47, 46, 51, 2, 92, 27, 55, 32, 51, 36, _
    92, 47, 25, 96, 43, 75, 38, 31, 24, 25)

For iI = 0 To 99
  iAr(iI) = vA(iI)
Next iI
  
Set vA = Nothing
ÁöµMÁÙ¬O·|¦h¦û¤@¨Ç³v­Óµ¹­Èªº®É¶¡(¦¹³B»P°²³]­ì¦CÁ|¦¡µ¹­ÈVBA¥i¥H±µ¨ü°µ¤ñ¸û)»P¤@­Ó Variant ªÅ¶¡,
¦ý·í°}¦C¸û¤j®É«oÀ³¸Ó¥i¥H¬Ù±¼º¡¦h°O¾ÐÅéªÅ¶¡, (¨Ò¦p»Ý­n°ÊºA·s¼W¤@­Ó Sheet ¨Ãµ¹©w¤@¨Ç Row »P Column ªºÄݩʤ§Ãþªº)
µ{¦¡·|¤ñ¸û®e©ö§PŪ§Y«K¦C¦L¤]¤£·|¤Óªø.

TOP

        ÀR«ä¦Û¦b : ¦³®É·í«äµL®É­W¡A¦n¤Ñ­n¿n«B¨Ó³¡C
ªð¦^¦Cªí ¤W¤@¥DÃD