excel_vba_±à³Ì½Ì³Ì(ÍêÕû°æ)-µÚ39²¿·Ö
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
×éÏàËƵÄÊýÖµ¡£Á½ÖÖ×îͨ³£µÄÊý×éÊÇһάÊý×飨Çåµ¥£©ºÍ¶þάÊý×飨±í¸ñ£©¡£ÓÐʱ£¬Ò»Î¬Êý×é±»³Æ¡¡
ΪÇåµ¥¡£Ò»Î¬Êý×é»ò±àºÅÇåµ¥µÄÀý×ÓÓУº¹ºÎïÇåµ¥£¬ÐÇÆÚÃû³ÆµÄÇåµ¥»òÔ±¹¤Çåµ¥¡£Çåµ¥ÀïÃæµÄÿ¸ö¡¡
Öµ¶¼ÓÐÒ»¸öË÷Òý¡£ÏÂÃæÊÇÒ»¸öº¬ÓÐÁù¸ö³ÉÔ±µÄÇåµ¥µÄͼ½â£º¡¡¡¡
ÏîÄ¿£¨1£©¡¡¡¡¡¡¡¡¡¡
ÏîÄ¿£¨2£©¡¡¡¡¡¡¡¡¡¡
ÏîÄ¿£¨3£©¡¡¡¡¡¡¡¡¡¡
ÏîÄ¿£¨4£©¡¡¡¡¡¡¡¡¡¡
ÏîÄ¿£¨5£©¡¡¡¡¡¡¡¡¡¡
ÏîÄ¿£¨6£©¡¡¡¡¡¡¡¡¡¡
×¢Ò⣬Áдú±íһάµÄµ±Ç°Îª¿ÕµÄÊý×é¡£Èç¹ûÄãÏëÓÃÊý¾ÝÌî³äÕâ¸öÊý×飬ֻҪʹÓÃÒ»¸ö±äÁ¿Ãû³Æ£¬¸½¡¡
´øÀ¨·û±àºÅ¾ÍÐУ¬¶ø²»ÐèҪʹÓÃÁù¸ö²»Í¬µÄ±êÇ©¡£ÔÚÉÏÃæµÄͼ½âÀ¡°ÏîÄ¿¡±Ò»±äÁ¿Ãû³Æ£¬À¨ºÅÀï¡¡
µÄÊý×ÖÃ÷È·Êý×éÀïµÄÿ¸ö³ÉÔ±¡£¡¡¡¡
Êý×éµÄËùÓгÉÔ±¶¼±ØÐë¾ßÓÐÏàͬµÄÊý¾ÝÀàÐÍ£¬»»¾ä»°Ëµ£¬Ò»¸öÊý×é²»ÄÜͬʱ´¢´æ×Ö·û´®ºÍÕûÐÍÊý¾Ý¡£¡¡
½ÓÏÂÀ´µÄͼ½âÊÇһάÊý×éµÄÁ½¸öÀý×Ó£ºµÚÒ»¸ö½Ð×öcitiesµÄһάÊý×éÓÉÎı¾×é³É£¨×Ö·û´®Êý¾ÝÀàÐÍ¡¡
¡ª¡ª£©£¬µÚ¶þ¸ö½Ð×ölottoµÄһάÊý×éÔò°üº¬Áù¸ö³é½±ºÅÂ루ÕûÊýÊý¾ÝÀàÐÍ¡ª¡ª£¥£©¡£¡¡¡¡
¡¡¡¡
¡¡¡¡¡¡¡¡Ò»Î¬Êý×écities¡¡£¨×Ö·û´®Êý¾ÝÀàÐÍ£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ò»Î¬Êý×élotto£¥¡¡£¨ÕûÊýÊý¾ÝÀàÐÍ£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cities£¨1£©¡¡¡¡Baltimore¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Lotto£¨1£©¡¡¡¡25¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cities£¨2£©¡¡¡¡Atlanta¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Lotto£¨2£©¡¡¡¡4¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cities£¨3£©¡¡¡¡Boston¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Lotto£¨3£©¡¡¡¡31¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cities£¨4£©¡¡¡¡Washington¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Lotto£¨4£©¡¡¡¡22¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cities£¨5£©¡¡¡¡New¡¡York¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Lotto£¨5£©¡¡¡¡11¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Cities£¨6£©¡¡¡¡Trenton¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Lotto£¨6£©¡¡¡¡5¡¡¡¡
¡¡¡¡
ÕýÈçÄã¿´µ½µÄ£¬Ã¿¸öÊý×é³ÉÔ±µÄÄÚÈݺͱäÁ¿µÄÊý¾ÝÀàÐÍÊÇÏàÆ¥ÅäµÄ¡£Èç¹ûÄãÏëÒªÔÚͬһ¸öÊý×éÀïÃæ¡¡
´¢´æ²»Í¬Êý¾ÝÀàÐ͵ÄÊý¾Ý£¬ÄÇôÄã±ØÐ뽫Êý¾ÝÉùÃ÷ΪVariant¡£¡¡¡¡
¶þάÊý×éÊÇÓÉÐкÍÁдú±íµÄÊý¾Ý±í¡£±íÖÐÿ¸ö³ÉÔ±µÄλÖÃÊÇÓÉËüµÄÐкÍÁкÅÂë¾ö¶¨µÄ¡£ÏÂÃæÊÇÒ»¸ö¡¡
¿ÕµÄ¶þάÊý×éµÄͼ½â¡£¡¡¡¡
¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Ðкš¡¡¡1¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Áкš¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡¡¡¡£¨1£»1£©¡¡¡¡¡¡¡¡¡¡¡¡£¨1£»2£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨1£»3£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡¡¡¡£¨2£»1£©¡¡¡¡¡¡¡¡¡¡¡¡£¨2£»2£©¡¡¡¡¡¡¡¡¡¡¡¡£¨2£»3£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡¡¡¡£¨3£»1£©¡¡¡¡¡¡¡¡¡¡¡¡£¨3£»2£©¡¡¡¡¡¡¡¡¡¡¡¡£¨3£»3£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡¡¡¡£¨4£»1£©¡¡¡¡¡¡¡¡¡¡¡¡£¨4£»2£©¡¡¡¡¡¡¡¡¡¡¡¡£¨4£»3£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡5¡¡¡¡£¨5£»1£©¡¡¡¡¡¡¡¡¡¡¡¡£¨5£»2£©¡¡¡¡¡¡¡¡¡¡¡¡£¨5£»3£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡
×¢Ò⣬¶þάÊý×éÀïµÄÏîÄ¿ÊÇÈçºÎÓÐÐкÍÁÐË÷ÒýÖ¸¶¨µÄ£¿ÔÚ¸Ãͼ½âÀÊý×éÀïµÄµÚÒ»¸ö³ÉԱλÓÚµÚÒ»¡¡
Ðк͵ÚÒ»ÁÐÀ1£»1£©£¬¶ø×îºóÒ»¸ö³ÉÔ±ÔòλÓÚµÚÎåÐк͵ÚÈýÁÐÀïµÄ£¨5£»3£©¡£ÏÂÃ棬ÎÒÃÇÀ´¸ø¸ÃÊý×éÌî¡¡
³äһЩÊý¾Ý¡£ÏÂÃæÏÔʾµÄ¶þάÊý×é´¢´æÁ˹ú¼ÒÃû³Æ£¬ËüµÄ»õ±ÒÃû³ÆÒÔ¼°ºÍÃÀÔªµÄ»ãÂÊ¡£¡¡¡¡
Japan¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Japanese¡¡Yen¡¡¡¡¡¡¡¡¡¡¡¡¡¡128¡£2¡¡¡¡
£¨1£»1£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨1£»2£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨1£»3£©¡¡¡¡
Mexico¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Mexican¡¡Peso¡¡¡¡¡¡¡¡¡¡¡¡¡¡9¡£423¡¡¡¡
£¨2£»1£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨2£»2£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨2£»3£©¡¡¡¡
Canada¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Canadian¡¡Dollar¡¡¡¡¡¡¡¡1¡£567¡¡¡¡
£¨3£»1£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨3£»2£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨3£»3£©¡¡¡¡
Norway¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Norwegian¡¡Krone¡¡¡¡¡¡¡¡8¡£351¡¡¡¡
£¨4£»1£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨4£»2£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨4£»3£©¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡123¡¡
¡¡¡Ò³Ãæ¡¡140¡
Hungary¡¡¡¡¡¡¡¡¡¡¡¡¡¡Hungarian¡¡Forint¡¡¡¡¡¡266¡£7¡¡¡¡
£¨5£»1£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨5£»2£©¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨5£»3£©¡¡¡¡
¾¡¹ÜVBAÊý×é×î´ó¿ÉÒÔÓµÓÐ60ά£¬µ«ÊÇ£¬¾ø´ó¶àÊýÈË·¢Ïַdz£À§ÄÑÈ¥ÏëÏ󳬹ýÈýάµÄÊý×é¡£ÈýάµÄ¡¡
Êý×éÊÇÒ»¸ö¾ßÓÐÏàͬÐÐÊýºÍÁÐÊýµÄ±í¸ñµÄ¼¯ºÏ¡£ÔÚÈýάÊý×éÀïµÄÿ¸ö³ÉÔ±ÓÉÏÂÃæÈý¸öÊý¾Ý¾ö¶¨£ºÐС¡
ºÅ£¬Áкźͱí¸ñºÅ¡£¡¡¡¡
¼¼ÇÉ7¡1¡¡Êý×é±äÁ¿ÊÇʲô£¿¡¡¡¡
Êý×éÊÇÓµÓй²Í¬Ãû³ÆµÄ±äÁ¿µÄ¼¯ºÏ¡£Ò»¸öµäÐ͵ıäÁ¿Ö»ÄÜ´¢´æÒ»¸öÊý¾Ý£¬È»¶ø£¬Ò»¸öÊý×é±äÁ¿È´ÄÜ¡¡
¹»´¢´æ´óÁ¿µÄ±äÁ¿¡£Äã¿ÉÒÔʹÓñäÁ¿Ãû³ÆºÍË÷ÒýºÅÀ´Ö¸ÏòÊý×éÖÐij¸öÈ·¶¨µÄÊý¾Ý¡£¡¡¡¡
¼¼ÇÉ7¡2¡¡Ï±ê±äÁ¿¡¡¡¡
Êý×é±äÁ¿µÄÀ¨ºÅÀïµÄÊý×Ö³ÉΪϱ꣬¶øÿ¸öµ¥¶ÀµÄ±äÁ¿Ôò³ÆΪϱê±äÁ¿»ò³ÉÔ±¡£ÀýÈ磬cities£¨6£©¡¡
ÊÇcitiesÊý×éÀïµÄµÚÁù¸öϱê±äÁ¿£¨³ÉÔ±£©¡£¡¡¡¡
2¡£ÉùÃ÷Êý×é¡¡¡¡
ÒòΪÊý×éÒ²ÊDZäÁ¿£¬ËùÒÔ£¬Äã±ØÐëÓÃÉùÃ÷ÆäËü±äÁ¿µÄÀàËÆ·½·¨ÉùÃ÷Êý×顪¡ªÊ¹ÓÃDimÓï¾ä¡£µ±ÄãÉù¡¡
Ã÷Ò»¸öÊý×éʱ£¬Äã±ãÉ趨Á˸ÃÊý×é´¢´æÊý¾ÝËùÐèÒªµÄÄÚ´æ¿Õ¼ä¡£¡¡¡¡
ÎÒÃÇÀ´¿´¿´Ò»¸öÊý×éÉùÃ÷µÄÀý×Ó£º¡¡¡¡
Dim¡¡cities£¨6£©¡¡As¡¡String¡¡¡¡¡¡
Dim¡¡daysOfWeek£¨7£©¡¡As¡¡String¡¡¡¡¡¡
Dim¡¡lotto£¨6£©¡¡As¡¡Integer¡¡¡¡¡¡
Dim¡¡exchange£¨5£»¡¡3£©¡¡As¡¡Variant¡¡¡¡¡¡
×¢Ò⣬±äÁ¿Ãû³ÆºóÃæ´øÓÐÀ¨ºÅÒÔ¼°À¨ºÅÀïÓÐÊý×Ö¡£Ò»Î¬Êý×éÒªÇóÀ¨ºÅÀï´øÒ»¸öÊý×Ö£¬Õâ¸öÊý×Ö¾ö¶¨¡¡
ÁËÕâ¸öÊý×éÄܹ»´¢´æµÄ×î´ó³ÉÔ±Êý¡£¶þάÊý×éºóÃæ×ÜÊÇ´øÓÐÁ½¸öÊý×Ö¡ª¡ªµÚÒ»¸öÊý×ÖÊÇÐÐË÷ÒýºÅ£¬¡¡
¶øµÚ¶þ¸öÊý×ÖÊÇÁÐË÷ÒýºÅ¡£ÔÚÉÏÃæµÄÀý×ÓÀÊý×éexchange×î¶à¿ÉÒÔ´¢´æ15¸öÊý¾Ý£¨5*3=15£©¡£¡¡¡¡
Êý×éÉùÃ÷µÄ×îºóÒ»²¿·ÝÊǶ¨ÒåÊý×齫Ҫ´¢´æÊý¾ÝµÄÊý¾ÝÀàÐÍ¡£Êý×é¿ÉÒÔ´¢´æÏÂÁÐÈκÎÒ»ÖÖÊý¾ÝÀà¡¡
ÐÍ£ºInteger£»¡¡Long£»¡¡Single£»¡¡Double£»¡¡Variant£»¡¡Currency£»¡¡String£»¡¡Boolean£»¡¡Byte£»¡¡or¡¡Date¡£¡¡¡¡
µ±ÄãÉùÃ÷ÁËÒ»¸öÊý×飬VB»á×Ô¶¯Õ¼¾Ý×ã¹»µÄÄÚ´æ¿Õ¼ä£¬·ÖÅäµÄÄÚ´æ¿Õ¼äÈ¡¾öÓÚ¸ÃÊý×éµÄ´óСºÍÊý¾Ý¡¡
ÀàÐÍ¡£µ±ÄãÉùÃ÷Ò»¸öÃû½ÐlottoµÄ´øÓÐ6¸ö³ÉÔ±µÄһάÊý×éʱ£¬VB½«Áô³ö12¸ö×Ö½Ú¡ª¡ªÊý×éµÄÿ¸ö³É¡¡
Ô±¸÷Õ¼2¸ö×Ö½Ú£¨»ØÏëÕûÐÍÊý¾ÝÀàÐÍΪ2¸ö×Ö½Ú£¬Òò´Ë2*6=12£©¡£Êý×éÔ½´ó£¬´¢´æÊý¾ÝÐèÒªµÄÄÚ´æ¿Õ¡¡
¼ä¾ÍÔ½´ó¡£ÒòΪÊý×é»á³ÔµôºÜ¶àÄڴ棬²¢Òò´ËÓ°ÏìÄãµçÄÔµÄÔËÐУ¬Òò´Ë£¬½¨ÒéÄã½ö½ö¸ù¾ÝÄã¿ÉÄÜʹ¡¡
ÓõijÉÔ±ÊýÀ´ÉùÃ÷Êý×é¡£¡¡¡¡
3¡£Êý×éµÄÉϽçºÍϽ硡¡¡
VBAĬÈϽ«Êý×éµÄµÚÒ»¸ö³ÉÔ±ÉèÖÃΪ0£¨ÒëÕߣºË÷ÒýºÅ£©£¬Òò´Ë£¬Êý×Ö1´ú±íÊý×éÖеĵڶþ¸ö³ÉÔ±£¬¶ø¡¡
Êý×Ö2Ôò´ú±íµÚÈý¸ö£¬µÈµÈ¡£ÒòΪÊý×Ö±àºÅÆðʼÓÚ0£¬ËùÒÔ£¬Ò»Î¬Êý×écities£¨6£©°üº¬´Ó0µ½6µÄÆ߸ö¡¡
³ÉÔ±¡£Èç¹ûÄãÄþÔ¸´Ó1¿ªÊ¼¼ÆÊýÄãÊý×éÀïµÄ³ÉÔ±£¬ÄÇôÄã¿ÉÒÔʹÓÃOption¡¡Base¡¡1Óï¾äÀ´Ç¿ÖÆÖ¸¶¨¸Ã¡¡
Êý×éµÄϽ硣¸ÃÖ¸Áî±ØÐëÖÃÓÚVBAÄ£¿éÈκÎSubÓï¾äÉÏÃæµÄÉùÃ÷²¿·Ö¡£Èç¹ûÄã²»Ã÷È·Option¡¡Base¡¡1£¬¡¡
ÄÇôVBAÔÚʹÓÃÊý×éÊǾͻá¼Ù¶¨Ê¹ÓÃOption¡¡Base¡¡0À´´Ó0¿ªÊ¼±àºÅÄãµÄÊý×é³ÉÔ±¡£¡¡¡¡
ÄãÒ²¿ÉÒÔÈÃÊý×é´Ó³ý0»ò1Ö®ÍâµÄÊý×Ö¿ªÊ¼±àºÅ£¬Òª´ïµ½¸ÃÄ¿µÄ£¬ÄãÔÚÉùÃ÷Êý×é±äÁ¿Ê±¾Í±ØÐëÃ÷È·¸Ã¡¡
Êý×éµÄ±ß½ç¡£Êý×éµÄ±ß½çÊÇÖ¸Ëü×îСºÍ×î´óµÄË÷ÒýºÅ¡£ÎÒÃÇÀ´¿´¿´ÏÂÃæµÄÀý×Ó£º¡¡¡¡
Dim¡¡cities£¨3¡¡To¡¡6£©¡¡As¡¡Integer¡¡¡¡¡¡
ÉÏÃæµÄÓï¾äÉùÃ÷ÁËÒ»¸ö´øÓÐËĸö³ÉÔ±µÄһάÊý×é¡£Êý×éÃû³ÆºóÃæÀ¨ºÅÀïµÄÊý×ÖÃ÷È·ÁËÊý×éµÄϽ硡
¡¡£¨3£©ºÍÉϽ磨6£©¡£¸ÃÊý×éµÄµÚÒ»¸ö³ÉÔ±±àºÅΪ3£¬µÚ¶þ¸öΪ4£¬µÚÈý¸öΪ5£¬ÒÔ¼°µÚËĸöΪ6¡£×¢Òâ¡¡
ϽçºÍÉϽçÖ®¼äµÄ¹Ø¼ü×ÖTo¡£¡¡¡¡
¼¼ÇÉ7¡3¡¡Êý×鷶Χ¡¡¡¡
DimÓï¾äÃ÷È·µÄÊý×éµÄϱêÇø¼ä¾Í³ÆΪÊý×éµÄ·¶Î§£¬ÀýÈ磺Dim¡¡mktgCodes£¨5¡¡To¡¡15£©¡¡¡¡
4¡£ÔÚ¡¡VBA¡¡¹ý³ÌÀïʹÓÃÊý×é¡¡¡¡
ÄãÉùÃ÷ÁËÊý×éºó£¬¾Í±ØÐë¸ø¸ÃÊý×éµÄÿ¸ö³ÉÔ±¸³Öµ£¬ÕâÒ²¾³£³ÉΪ¡°Ìî³äÊý×顱¡£ÎÒÃÇÀ´³¢ÊÔʹÓá¡
һάÊý×éÓй滮µØÏÔʾÁù¸öÃÀ¹ú³ÇÊеÄÇåµ¥£º¡¡¡¡
1¡£¡¡¡¡´ò¿ªÒ»¸öй¤×÷²¾£¬²¢±£´æΪChap07¡£xls¡¡¡¡
2¡£¡¡¡¡Çл»µ½VB±à¼Æ÷´°¿Ú£¬²¢ÖØÐÂÃüÃûVBA¹¤³ÌΪTables¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡124¡¡
¡¡¡Ò³Ãæ¡¡141¡
3¡£¡¡¡¡²åÈëÒ»ÐÂÄ£¿é£¬ÖØÐÂÃüÃûΪStaticArrays¡¡¡¡
4¡£¡¡¡¡ÊäÈëÏÂÁйý³ÌFavoriteCities£º¡¡¡¡
'¡¡start¡¡indexing¡¡array¡¡elements¡¡at¡¡1¡¡´Ó1¿ªÊ¼¸øÊý×é³ÉÔ±±àºÅ¡¡¡¡
Option¡¡Base¡¡1¡¡¡¡¡¡
Sub¡¡FavoriteCities£¨£©¡¡¡¡¡¡
'now¡¡declare¡¡the¡¡array¡¡¡¡¡¡
Dim¡¡cities£¨6£©¡¡As¡¡String¡¡¡¡¡¡
'assign¡¡the¡¡values¡¡to¡¡array¡¡elements¡¡¡¡¡¡
cities£¨1£©¡¡=¡¡¡¨Baltimore¡¨¡¡¡¡¡¡
cities£¨2£©¡¡=¡¡¡¨Atlanta¡¨¡¡¡¡¡¡
cities£¨3£©¡¡=¡¡¡¨Boston¡¨¡¡¡¡¡¡
cities£¨4£©¡¡=¡¡¡¨Washington¡¨¡¡¡¡¡¡
cities£¨5£©¡¡=¡¡¡¨New¡¡York¡¨¡¡¡¡¡¡
cities£¨6£©¡¡=¡¡¡¨Trenton¡¨¡¡¡¡¡¡
'display¡¡the¡¡list¡¡of¡¡cities¡¡¡¡¡¡
MsgBox¡¡cities£¨1£©¡¡&¡¡Chr£¨13£©¡¡&¡¡cities£¨2£©¡¡&¡¡Chr£¨13£©¡¡_¡¡¡¡¡¡
¡¡¡¡&¡¡cities£¨3£©¡¡&¡¡Chr£¨13£©¡¡&¡¡cities£¨4£©¡¡&¡¡Chr£¨13£©¡¡_¡¡¡¡¡¡
¡¡¡¡&¡¡cities¡¡£¨5£©¡¡&¡¡Chr£¨13£©¡¡&¡¡cities£¨6£©¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
ÔÚFavoriteCities¹ý³Ì¿ªÊ¼Ö®Ç°£¬È±Ê¡µÄË÷Òý±àºÅ·½Ê½¸Ä±äÁË£¬×¢Ò⣬Option¡¡Base¡¡1Óï¾äÊÇλÓÚ¡¡
Ä£¿é´°¿ÚSubÓï¾äÖ®Éϵġ£¸ÃÓï¾ä¸æËßVB¸øÊý×éµÄµÚÒ»¸ö³ÉÔ±¸³ÖµÊý×Ö1£¬¶ø²»ÊÇȱʡµÄ0¡£¡¡¡¡
Êý×écities£¨£©ÉùÃ÷Ϊ´øÁù¸ö³ÉÔ±µÄ×Ö·û´®ÀàÐͱäÁ¿¡£È»ºó£¬¸øÊý×éµÄÿ¸ö³ÉÔ±¶¼¸³ÉÏÁËÖµ¡£×îºóµÄ¡¡
Óï¾äʹÓÃMsgboxº¯ÊýÏÔʾ³ÇÊÐÇåµ¥¡£µ±ÄãÔËÐиùý³Ìʱ£¬³ÇÊÐÃû³Æ½«»á³öÏÖÔÚ·Ö¿ªµÄÐÐÉÏ£¨²Î¼ûͼ¡¡
7¡1£©¡£Äã¿ÉÒԸıäÏÔʾÊý¾ÝµÄ˳Ðò£¬¸Ä±äË÷ÒýºÅ¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ͼ7¡1¡¡Äã¿ÉÒÔÓÃMsgboxº¯ÊýÀ´ÏÔʾһάÊý×éµÄ³ÉÔ±¡¡¡¡
5¡£¡¡¡¡ÔËÐÐFavoriteCities¹ý³Ì²¢ÇÒ¼ì²é½á¹û¡¡¡¡
6¡£¡¡¡¡ÐÞ¸ÄFavoriteCities¹ý³Ì£¬ÈÃËüÄæÐòÏÔʾ³ÇÊÐÃû³Æ£¨´Ó6µ½1£©¡¡¡¡
¼¼ÇÉ7¡4¡¡Êý×é³ÉÔ±µÄ³õʼֵ¡¡¡¡
ÔÚ¸øÊý×é³ÉÔ±¸³ÖµÖ®Ç°£¬¸Ã³ÉÔ±¾ßÓÐȱʡֵ¡£Êý×Ö±äÁ¿µÄȱʡֵΪ0£¬¶ø×Ö·û´®±äÁ¿µÄȱʡֵΪ¿Õ¡¡
×Ö·û´®¡£¡¡¡¡
5¡£Êý×éºÍÑ»·Óï¾ä¡¡¡¡
ÏÖÔÚÒªÖ´ÐÐһЩÀýÈçÌî³äÊý×é»òÏÔʾÊý×é³ÉÔ±µÄÈÎÎñÁË£¬ÄãÔÚµÚÁùÕÂÀïѧ¹ýµÄºÃЩ¸öÑ»·Óï¾ä£¨²Î¡¡
¼ûFor¡NextºÍFor¡¡Each¡¡¡NextÑ»·£©¾Í±äµÃ·Ç³£·½±ãÁË¡£ÏÖÔÚÊÇʱºò½«ÄãËùѧµ½µÄ¼¼ÇɽáºÏÆðÀ´¡¡
ʹÓÃÁË¡£ÈçºÎÖØбàдFavoriteCities¹ý³Ì£¬ÈÃÿ¸ö³ÇÊÐÃû³ÆÔÚ²»Í¬µÄÐÅÏ¢¿òÀïÏÔʾ³öÀ´£¿¡¡¡¡
ÏÂÃæÏÔʾµÄ¹ý³ÌFavoriteCities2½«ÔÀ´¹ý³ÌµÄ×îºó²¿·ÖÈ¡´úΪFor¡¡Each¡NextÑ»·£º¡¡¡¡
Sub¡¡FavoriteCities2£¨£©¡¡¡¡¡¡
¡¡¡¡'now¡¡declare¡¡the¡¡array¡¡¡¡¡¡
¡¡¡¡Dim¡¡cities£¨6£©¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡Dim¡¡city¡¡As¡¡Variant¡¡¡¡¡¡
¡¡¡¡'assign¡¡the¡¡values¡¡to¡¡array¡¡elements¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡125¡¡
¡¡¡Ò³Ãæ¡¡142¡
¡¡¡¡cities£¨1£©¡¡=¡¡¡¨Baltimore¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨2£©¡¡=¡¡¡¨Atlanta¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨3£©¡¡=¡¡¡¨Boston¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨4£©¡¡=¡¡¡¨Washington¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨5£©¡¡=¡¡¡¨New¡¡York¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨6£©¡¡=¡¡¡¨Trenton¡¨¡¡¡¡¡¡
¡¡¡¡'display¡¡the¡¡list¡¡of¡¡cities¡¡in¡¡separate¡¡messages¡¡¡¡¡¡
¡¡¡¡For¡¡Each¡¡city¡¡in¡¡cities¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡city¡¡¡¡¡¡
¡¡¡¡Next¡¡¡¡¡¡
End¡¡Sub¡¡¡¡
×¢ÒâFor¡¡Each¡NextÑ»·Ê¹ÓõÄÊÇVariantÊý¾ÝÀàÐ͵ıäÁ¿city¡£»ØÏëÔÚÇ°ÃæµÄÕ½ÚÀFor¡¡¡¡
Each¡NextÈÃÄãÔÚÒ»¸ö¼¯ºÏµÄËùÓжÔÏó¼ä»òÕßÒ»¸öÊý×éµÄËùÓеijÉÔ±¼äÑ»·£¬²¢ÇÒ¶Ôÿ¸ö¶ÔÏó»ò³É¡¡
Ô±Ö´ÐÐͬÑùµÄ²Ù×÷¡£µ±ÄãÔËÐйý³ÌFavoriteCities2ʱ£¬Êý×éÀïÓм¸¸ö³ÉԱѻ·¾Í»áÖ´Ðм¸´Î¡£¡¡¡¡
ÎÒÃÇÀ´¿´Ò»Ï¹ý³ÌFavoriteCitiesµÄÁíÒ»Öֱ仯¡£ÔÚµÚËÄÕÂÀÄãÁ·Ï°Á˽«²ÎÊý×÷Ϊ±äÁ¿´«µÝ¸ø×Ó¡¡
¹ý³ÌºÍº¯Êý¡£¹ý³ÌFavoriteCities3ʾ·¶ÁËÈçºÎ½«Êý×éµÄ³ÉÔ±´«µÝ¸øÁíÒ»¸ö¹ý³Ì¡£¡¡¡¡
1¡£¡¡¡¡ÔÚµ±Ç°Ä£¿éÀÊäÈëÏÂÊöÁ½¸ö¹ý³Ì£º¡¡¡¡
Sub¡¡FavoriteCities3£¨£©¡¡¡¡¡¡
¡¡¡¡'now¡¡declare¡¡the¡¡array¡¡¡¡¡¡
¡¡¡¡Dim¡¡cities£¨6£©¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡'assign¡¡the¡¡values¡¡to¡¡array¡¡elements¡¡¡¡¡¡
¡¡¡¡cities£¨1£©¡¡=¡¡¡¨Baltimore¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨2£©¡¡=¡¡¡¨Atlanta¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨3£©¡¡=¡¡¡¨Boston¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨4£©¡¡=¡¡¡¨Washington¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨5£©¡¡=¡¡¡¨New¡¡York¡¨¡¡¡¡¡¡
¡¡¡¡cities£¨6£©¡¡=¡¡¡¨Trenton¡¨¡¡¡¡¡¡
¡¡¡¡'call¡¡another¡¡procedure¡¡and¡¡pass¡¡the¡¡array¡¡as¡¡argument¡¡¡¡¡¡
¡¡¡¡Hallo¡¡cities£¨£©¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
Sub¡¡Hallo¡¡£¨cities£¨£©¡¡As¡¡String£©¡¡¡¡¡¡
¡¡¡¡Dim¡¡counter¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡For¡¡counter¡¡=¡¡1¡¡to¡¡6¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡¡¨Hello¡¡¡¨¡¡&¡¡cities£¨counter£©¡¡¡¡¡¡
¡¡¡¡Next¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
¹ý³ÌHalloµÄÉùÃ÷ÀïÓÐÒ»¸öÊý×éÀàÐ͵IJÎÊý¡ª¡ªcities£¨£©¡£¡¡¡¡
2¡£¡¡¡¡ÔËÐйý³ÌFavoriteCities3¡£½«Ò»¸ö×Ó¹ý³ÌµÄÊý×é³ÉÔ±´«µÝ¸øÁíÒ»¸ö×Ó¹ý³Ì»òÕߺ¯Êý¹ý³ÌÈÃÄã¡¡
¡¡¡¡¡¡¡¡¿ÉÒÔÔÚÐí¶à¹ý³ÌÀïʹÓÃÏàͬµÄÊý×飬¶ø²»ÐèÒªÖظ´µÄ³ÌÐò´úÂë¡£¡¡¡¡
¼¼ÇÉ7¡5¡¡ÔÚ¹ý³ÌÖ®¼ä´«µÝÊý×é¡¡¡¡
µ±Ò»¸öÊý×éÔÚÒ»¸ö¹ý³ÌÀï±»ÉùÃ÷ʱ£¬ËüÊǾֲ¿µÄ£¬²¢ÇÒÊDz»ÎªÆäËû¹ý³ÌËùÖªµÄ¡£È»¶ø£¬Äã¿ÉÒÔ½«¾Ö¡¡
²¿Êý×é´«µÝ¸øÆäËüµÄ¹ý³Ì£¬Í¨¹ýÔÚÉùÃ÷Óï¾äÀдÉÏÊý×éÃû³Æ£¬²¢ÇÒºóÃæ½ô¸úÒ»¶Ô¿ÕÀ¨ºÅ¡£ÀýÈ磬¡¡
Óï¾äHallo¡¡cities£¨£©¡¡µ÷Ó