ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
¸»Ê¿¿µÐ¡ËµÍø ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ6²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡



in¡¡the¡¡source¡¡code¡£¡¡Then¡¡if¡¡you¡¡e¡¡back¡¡to¡¡the¡¡application¡¡in¡¡the¡¡future£»¡¡you¡¡won¡¯t¡¡be¡¡puzzled¡¡¡¡

by¡¡your¡¡previous¡¡work¡£¡¡In¡¡fact£»¡¡you¡¡may¡¡not¡¡even¡¡be¡¡the¡¡person¡¡who¡¡maintains¡¡your¡¡code£»¡¡so¡¡¡¡

leaving¡¡ments¡¡in¡¡the¡¡code¡¡to¡¡help¡¡explain¡¡it¡¡is¡¡definitely¡¡good¡¡practice¡£¡¡Even¡¡if¡¡you¡¡know¡¡¡¡

you¡¡will¡¡be¡¡maintaining¡¡the¡¡code¡¡forever£»¡¡treat¡¡your¡¡future¡¡self¡¡as¡¡a¡¡stranger¡£¡¡You¡¡may¡¡be¡¡surprised¡¡¡¡

how¡¡long¡¡it¡¡takes¡¡to¡¡decipher¡¡code¡¡you¡¡have¡¡written¡¡when¡¡revisited¡¡months¡¡or¡¡years¡¡later¡£¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡add¡¡a¡¡single¡­line¡¡ment£»¡¡use¡¡the¡¡following¡¡syntax£º¡¡



¡¡'¡¡A¡¡single¡­line¡¡ment¡¡



¡¡¡¡¡¡¡¡¡¡Anything¡¡after¡¡the¡¡¡¡'¡¡on¡¡the¡¡same¡¡line¡¡is¡¡ignored¡¡by¡¡the¡¡piler¡¡and¡¡is¡¡not¡¡included¡¡in¡¡the¡¡¡¡

final¡¡application¡£¡¡Let¡¯s¡¡document¡¡our¡¡Windows¡¡application£º¡¡



¡¡'¡¡When¡¡the¡¡user¡¡clicks¡¡the¡¡button£»¡¡we¡¡display¡¡text¡¡in¡¡the¡¡text¡¡box¡¡

¡¡¡¡¡¡¡¡Private¡¡Sub¡¡Button1_Click£¨ByVal¡¡sender¡¡As¡¡System¡£Object£»¡¡¡¡

ByVal¡¡e¡¡As¡¡System¡£EventArgs£©¡¡Handles¡¡Button1¡£Click¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextBox1¡£Text¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡Visual¡¡Basic¡¡language¡¡is¡¡a¡¡single¡­line¡¡language¡£¡¡This¡¡means¡¡that¡¡a¡¡statement¡¡must¡¡be¡¡¡¡

part¡¡of¡¡a¡¡single¡¡line¡£¡¡Let¡¯s¡¡look¡¡at¡¡a¡¡single¡¡statement£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextBox1¡£Text¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡



¡¡¡¡¡¡¡¡¡¡This¡¡line¡¡of¡¡code¡¡is¡¡a¡¡single¡¡statement¡¡because¡¡it¡¡is¡¡considered¡¡an¡¡assignment¡¡of¡¡one¡¡variable¡¡¡¡

by¡¡another¡¡piece¡¡of¡¡source¡¡code¡£¡¡You¡¡could¡¡not¡¡write¡¡the¡¡statement¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextBox1¡£Text¡¡=¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨hello£»¡¡world¡¨¡¡



¡¡¡¡¡¡¡¡¡¡When¡¡the¡¡statement¡¡is¡¡broken¡¡into¡¡two¡¡lines¡¡of¡¡source¡¡code£»¡¡the¡¡Visual¡¡Basic¡¡piler¡¡sees¡¡¡¡

it¡¡as¡¡two¡¡statements¡£¡¡Since¡¡those¡¡two¡¡statements¡¡are¡¡not¡¡plete£»¡¡a¡¡pilation¡¡error¡¡will¡¡¡¡

result¡£¡¡If¡¡you¡¡need¡¡to¡¡break¡¡a¡¡single¡¡statement¡¡over¡¡two¡¡lines£»¡¡you¡¡must¡¡let¡¡the¡¡piler¡¡know¡¡¡¡

by¡¡adding¡¡the¡¡line¡­continuation¡¡character¡ªan¡¡underscore¡¡£¨_£©¡ªat¡¡the¡¡end¡¡of¡¡the¡¡continued¡¡¡¡

code£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TextBox1¡£Text¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨hello£»¡¡world¡¨¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡34¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

12¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡ST¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡G¡¡O¡¡£¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Navigating¡¡the¡¡User¡¡Controls¡¡of¡¡the¡¡Solution¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡you¡¡are¡¡writing¡¡your¡¡code£»¡¡your¡¡most¡¡important¡¡form¡¡of¡¡navigation¡¡is¡¡the¡¡Solution¡¡Explorer¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Solution¡¡Explorer¡¡is¡¡the¡¡tree¡¡control¡¡that¡¡contains¡¡the¡¡references¡¡to¡¡your¡¡solutions¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡projects¡£¡¡Consider¡¡the¡¡Solution¡¡Explorer¡¡as¡¡your¡¡developer¡¡dashboard£»¡¡which¡¡you¡¡can¡¡use¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡fine¡­tune¡¡how¡¡your¡¡¡¡application¡¡is¡¡assembled¡¡and¡¡executed¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡I¡¡suggest¡¡that¡¡you¡¡take¡¡a¡¡moment¡¡to¡¡click¡¡around¡¡the¡¡Solution¡¡Explorer¡£¡¡Try¡¡some¡¡right

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡clicks¡¡on¡¡various¡¡elements¡£¡¡The¡¡context¡­sensitive¡¡click¡¡is¡¡a¡¡fast¡¡way¡¡of¡¡fine¡­tuning¡¡particular¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡aspects¡¡of¡¡your¡¡solution¡¡and¡¡project¡£¡¡However£»¡¡when¡¡clicking£»¡¡please¡¡do¡¡not¡¡click¡¡OK¡¡in¡¡any¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dialog¡¡box£»¡¡for¡¡now£»¡¡click¡¡Cancel¡¡so¡¡that¡¡any¡¡changes¡¡you¡¡may¡¡have¡¡made¡¡are¡¡not¡¡saved¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡the¡¡right¡¡of¡¡the¡¡Solution¡¡Explorer¡¡is¡¡your¡¡work¡¡area¡£¡¡The¡¡work¡¡area¡¡is¡¡where¡¡you¡¡write¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡code¡¡or¡¡edit¡¡your¡¡user¡¡interface¡£¡¡The¡¡work¡¡area¡¡will¡¡display¡¡only¡¡a¡¡single¡¡piece¡¡of¡¡informa

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tion£»¡¡which¡¡could¡¡be¡¡some¡¡code£»¡¡a¡¡user¡¡interface£»¡¡or¡¡a¡¡project¡£¡¡As¡¡you¡¡saw¡¡earlier£»¡¡when¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡double¡­click¡¡Form1¡£vb¡¡in¡¡the¡¡Solution¡¡Explorer£»¡¡the¡¡work¡¡area¡¡displays¡¡the¡¡form¡¡related¡¡to¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Form1¡£vb¡¡file¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡you¡¡have¡¡an¡¡idea¡¡of¡¡how¡¡the¡¡IDE¡¡works£»¡¡let¡¯s¡¡continue¡¡with¡¡our¡¡examples¡£¡¡Next¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡up¡¡is¡¡the¡¡console¡¡application¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Creating¡¡the¡¡Console¡¡Application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡console¡¡application¡¡is¡¡a¡¡text¡­based¡¡application¡£¡¡This¡¡means¡¡that¡¡rather¡¡than¡¡displaying¡¡a¡¡GUI£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡it¡¡uses¡¡a¡¡mand¡­line¡¡interface¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡console¡¡has¡¡a¡¡very¡¡long¡¡history¡¡because¡¡the¡¡console¡¡was¡¡the¡¡first¡¡way¡¡to¡¡interact¡¡with¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡puter¡£¡¡Consoles¡¡are¡¡not¡¡very¡¡user¡­friendly¡¡and¡¡bee¡¡very¡¡tedious¡¡for¡¡any¡¡plex¡¡oper

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ations£»¡¡yet¡¡some¡¡people¡¡claim¡¡that¡¡a¡¡console¡¡is¡¡all¡¡you¡¡need¡£¡¡£¨See¡¡http£º//en¡£wikipedia¡£org/¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡wiki/mand_line_interface¡¡for¡¡more¡¡information¡¡about¡¡the¡¡console¡££©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Writing¡¡to¡¡the¡¡console¡¡works¡¡only¡¡if¡¡the¡¡currently¡¡running¡¡application¡¡has¡¡a¡¡console¡£¡¡To¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡open¡¡the¡¡console¡¡in¡¡Windows£»¡¡select¡¡Start¡¡¡¡Run¡¡and¡¡type¡¡cmd¡¡in¡¡the¡¡dialog¡¡box¡£¡¡When¡¡you¡¡test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡console¡¡application£»¡¡Visual¡¡Basic¡¡Express¡¡opens¡¡a¡¡console¡¡for¡¡you¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡Express¡¡can¡¡create£»¡¡build£»¡¡and¡¡manage¡¡console¡¡applications¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Adding¡¡a¡¡Console¡¡Application¡¡Project¡¡to¡¡the¡¡Solution¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡will¡¡now¡¡create¡¡an¡¡application¡¡that¡¡outputs¡¡the¡¡text¡¡¡°hello£»¡¡world¡±¡¡to¡¡the¡¡console¡£¡¡Follow¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡these¡¡steps¡¡to¡¡add¡¡the¡¡new¡¡project¡¡to¡¡the¡¡ThreeExamples¡¡solution£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡Choose¡¡File¡¡¡¡Add¡¡¡¡New¡¡Project¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡Make¡¡sure¡¡the¡¡location¡¡is¡¡the¡¡same¡¡as¡¡that¡¡of¡¡WindowsApplication¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡Select¡¡Console¡¡Application¡¡and¡¡change¡¡the¡¡name¡¡to¡¡ConsoleApplication¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Solution¡¡Explorer¡¡changes¡¡to¡¡show¡¡the¡¡additional¡¡project¡¡and¡¡now¡¡also¡¡shows¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡solution¡£¡¡The¡¡work¡¡area¡¡displays¡¡the¡¡source¡¡code¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Notice¡¡the¡¡simplicity¡¡of¡¡the¡¡console¡¡application¡£¡¡It¡¡contains¡¡a¡¡single£»¡¡plain¡­vanilla¡¡source¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡file£»¡¡called¡¡Module1¡£vb¡£¡¡Console¡¡applications¡¡typically¡¡do¡¡not¡¡have¡¡any¡¡specialized¡¡group

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ings¡¡and¡¡do¡¡not¡¡have¡¡any¡¡events¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡35¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡13¡¡



Making¡¡the¡¡Console¡¡Application¡¡Say¡¡Hello¡¡



To¡¡make¡¡the¡¡console¡¡application¡¡do¡¡something£»¡¡you¡¡need¡¡to¡¡add¡¡some¡¡source¡¡code¡¡to¡¡the¡¡¡¡

Main£¨£©¡¡method£»¡¡as¡¡follows£º¡¡



Module¡¡Module1¡¡



¡¡¡¡¡¡¡¡Sub¡¡Main£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨hello£»¡¡world¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£ReadKey£¨£©¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡



End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡bolded¡¡line¡¡writes¡¡the¡¡text¡¡¡°hello£»¡¡world¡±¡¡to¡¡the¡¡console¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡tried¡¡to¡¡run¡¡the¡¡console¡¡application¡¡by¡¡pressing¡¡Ctrl£«F5£»¡¡you¡¡would¡¡instead¡¡cause¡¡¡¡

the¡¡Windows¡¡application£»¡¡WindowsApplication£»¡¡to¡¡run¡£¡¡Let¡¯s¡¡change¡¡that¡¡next¡£¡¡¡¡



Setting¡¡the¡¡Startup¡¡Project¡¡



To¡¡execute¡¡the¡¡console¡¡application£»¡¡you¡¡need¡¡to¡¡set¡¡the¡¡console¡¡application¡¡as¡¡the¡¡startup¡¡project¡£¡¡¡¡

Did¡¡you¡¡notice¡¡how¡¡the¡¡WindowsApplication¡¡project¡¡is¡¡in¡¡bold¡¡in¡¡the¡¡Solution¡¡Explorer£¿¡¡That¡¡¡¡

means¡¡WindowsApplication¡¡is¡¡the¡¡startup¡¡project¡£¡¡Whenever¡¡you¡¡run¡¡or¡¡debug¡¡an¡¡application£»¡¡¡¡

the¡¡startup¡¡project¡¡is¡¡executed¡¡or¡¡debugged¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡switch¡¡the¡¡startup¡¡project¡¡to¡¡ConsoleApplication£»¡¡right¡­click¡¡the¡¡ConsoleApplication¡¡¡¡

project¡¡and¡¡select¡¡Set¡¡As¡¡StartUp¡¡Project¡£¡¡ConsoleApplication¡¡will¡¡now¡¡be¡¡in¡¡bold£»¡¡meaning¡¡it¡¡is¡¡¡¡

the¡¡startup¡¡project¡¡of¡¡the¡¡ThreeExamples¡¡solution¡£¡¡



Running¡¡the¡¡Console¡¡Project¡¡



With¡¡ConsoleApplication¡¡set¡¡as¡¡the¡¡startup¡¡project£»¡¡you¡¡can¡¡now¡¡press¡¡Ctrl£«F5¡¡to¡¡run¡¡the¡¡¡¡

console¡¡application¡£¡¡The¡¡output¡¡is¡¡as¡¡follows£º¡¡



hello£»¡¡world¡¡



¡¡¡¡¡¡¡¡¡¡Executing¡¡the¡¡console¡¡application¡¡does¡¡not¡¡generate¡¡a¡¡window£»¡¡as¡¡you¡¡saw¡¡with¡¡the¡¡Windows¡¡¡¡

application¡£¡¡Instead£»¡¡a¡¡mand¡¡prompt¡¡is¡¡started¡¡with¡¡ConsoleApplication¡¡as¡¡the¡¡application¡¡¡¡

to¡¡execute¡£¡¡Executing¡¡that¡¡application¡¡generates¡¡the¡¡text¡¡¡°hello£»¡¡world¡£¡±¡¡You¡¡will¡¡also¡¡see¡¡that¡¡¡¡

you¡¡can¡¡press¡¡any¡¡key¡¡to¡¡close¡¡the¡¡mand¡¡prompt¡¡window¡£¡¡Visual¡¡Basic¡¡Express¡¡automati

cally¡¡generated¡¡the¡¡code¡¡to¡¡show¡¡this¡¡output¡¡and¡¡execute¡¡this¡¡action¡£¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡general£»¡¡the¡¡console¡¡application¡¡is¡¡limited£»¡¡but¡¡it¡¯s¡¡an¡¡easy¡¡way¡¡to¡¡run¡¡specific¡¡tasks¡£¡¡¡¡

Now¡¡let¡¯s¡¡move¡¡on¡¡to¡¡the¡¡next¡¡example¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡36¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

14¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡ST¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡G¡¡O¡¡£¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Creating¡¡the¡¡Class¡¡Library¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡third¡¡example¡¡in¡¡this¡¡chapter¡¡is¡¡not¡¡a¡¡¡¡application£»¡¡rather£»¡¡it¡¡is¡¡a¡¡shareable¡¡piece¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡functionality£»¡¡typically¡¡called¡¡a¡¡¡¡class¡¡library¡£¡¡Windows¡¡applications¡¡and¡¡console¡¡applications¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡are¡¡programs¡¡that¡¡you¡¡can¡¡execute¡¡from¡¡a¡¡mand¡¡prompt¡¡or¡¡Windows¡¡Explorer¡£¡¡A¡¡class¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡library¡¡cannot¡¡be¡¡executed¡¡by¡¡the¡¡user£»¡¡but¡¡needs¡¡to¡¡be¡¡accessed¡¡by¡¡a¡¡Windows¡¡application¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡console¡¡application¡£¡¡It¡¡is¡¡a¡¡convenient¡¡place¡¡to¡¡put¡¡code¡¡that¡¡can¡¡be¡¡used¡¡by¡¡more¡¡than¡¡one¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡application¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Adding¡¡a¡¡Class¡¡Library¡¡Project¡¡to¡¡the¡¡Solution¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡will¡¡now¡¡create¡¡a¡¡class¡¡library¡¡for¡¡the¡¡Windows¡¡application¡¡and¡¡console¡¡application¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡share¡£¡¡Follow¡¡these¡¡steps¡¡to¡¡add¡¡the¡¡new¡¡project¡¡to¡¡the¡¡ThreeExamples¡¡solution£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡Right¡­click¡¡the¡¡solution¡¡name£»¡¡ThreeExamples£»¡¡in¡¡the¡¡Solution¡¡Explorer¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Select¡¡Add¡¡¡¡New¡¡Project¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡Select¡¡Class¡¡Library¡¡and¡¡change¡¡the¡¡name¡¡to¡¡ClassLibrary¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡resulting¡¡solution¡¡project¡¡should¡¡look¡¡like¡¡Figure¡¡1¡­8¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­8¡£¡¡¡¡Updated¡¡solution¡¡structure¡¡that¡¡contains¡¡three¡¡projects¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡added¡¡ClassLibrary¡¡project¡¡has¡¡a¡¡single¡¡file¡¡called¡¡Class1¡£vb£»¡¡which¡¡is¡¡a¡¡plain¡­vanilla¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡source¡¡code¡¡file¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡37¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡15¡¡



Moving¡¡Functionality¡¡



Now¡¡we¡¡will¡¡move¡¡the¡¡code¡¡used¡¡to¡¡say¡¡¡°hello£»¡¡world¡±¡¡from¡¡ConsoleApplication¡¡to¡¡¡¡

ClassLibrary¡£¡¡Add¡¡the¡¡code¡¡to¡¡Class1¡£vb¡¡as¡¡follows¡¡£¨the¡¡bolded¡¡code£©£º¡¡



Public¡¡Class¡¡Class1¡¡

¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Sub¡¡HelloWorld£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨hello£»¡¡world¡¨£©¡¡

¡¡¡¡¡¡¡¡End¡¡Sub¡¡

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡modified¡¡code¡¡contains¡¡a¡¡method¡¡called¡¡HelloWorld£¨£©¡£¡¡When¡¡called£»¡¡this¡¡method¡¡will¡¡¡¡

output¡¡the¡¡text¡¡¡°hello£»¡¡world¡£¡±¡¡As¡¡mentioned¡¡earlier¡¡in¡¡the¡¡chapter£»¡¡a¡¡method¡¡is¡¡a¡¡set¡¡of¡¡instruc

tions¡¡that¡¡carry¡¡out¡¡a¡¡task¡£¡¡Methods¡¡are¡¡discussed¡¡in¡¡more¡¡detail¡¡in¡¡Chapter¡¡2¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡order¡¡for¡¡applications¡¡to¡¡actually¡¡share¡¡the¡¡code¡¡that¡¯s¡¡in¡¡a¡¡class¡¡library£»¡¡you¡¡must¡¡make¡¡¡¡

the¡¡projects¡¡aware¡¡of¡¡each¡¡other¡¯s¡¡existence¡£¡¡You¡¡do¡¡that¡¡through¡¡references¡£¡¡



Defining¡¡References¡¡



To¡¡make¡¡one¡¡project¡¡aware¡¡of¡¡definitions¡¡in¡¡another¡¡project£»¡¡you¡¡need¡¡to¡¡define¡¡a¡¡reference¡£¡¡The¡¡¡¡

idea¡¡behind¡¡a¡¡reference¡¡is¡¡to¡¡indicate¡¡that¡¡a¡¡project¡¡knows¡¡about¡¡another¡¡piece¡¡of¡¡functionality¡£¡¡



¡öNote¡¡¡¡The¡¡project¡¡only¡¡knows¡¡about¡¡the¡¡functionality¡¡that¡¡has¡¡been¡¡declared¡¡as¡¡being¡¡public¡£¡¡Public¡¡function

ality£»¡¡or¡¡what¡¡Visual¡¡Basic¡¡programmers¡¡call¡¡public¡¡scope£»¡¡is¡¡when¡¡you¡¡declare¡¡a¡¡type¡¡with¡¡the¡¡Public¡¡keyword¡£¡¡¡¡

You¡¡will¡¡learn¡¡about¡¡public¡¡and¡¡other¡¡scopes¡¡throughout¡¡this¡¡book¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡To¡¡make¡¡ConsoleApplication¡¡aware¡¡of¡¡the¡¡functionality¡¡in¡¡the¡¡ClassLibrary¡¡project£»¡¡you¡¡¡¡

need¡¡to¡¡set¡¡a¡¡physical¡¡reference£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡In¡¡the¡¡Solution¡¡Explorer£»¡¡click¡¡ConsoleApplication¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Right¡­click¡¡and¡¡select¡¡Add¡¡Reference¡£¡¡



¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡Click¡¡the¡¡Projects¡¡tab¡£¡¡



¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡Select¡¡ClassLibrary£»¡¡and¡¡then¡¡click¡¡OK¡£¡¡ClassLibrary¡¡will¡¡be¡¡added¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ConsoleApplication¡¯s¡¡references¡£¡¡



¡¡¡¡¡¡¡¡¡¡Once¡¡the¡¡reference¡¡has¡¡been¡¡assigned£»¡¡ConsoleApplication¡¡can¡¡call¡¡the¡¡functionality¡¡in¡¡¡¡

ClassLibrary¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡know¡¡which¡¡references¡¡your¡¡application¡¡or¡¡class¡¡library¡¡has£»¡¡you¡¡need¡¡to¡¡look¡¡in¡¡the¡¡¡¡

project¡¡settings¡£¡¡To¡¡do¡¡so£»¡¡right¡­click¡¡the¡¡project¡¡name£»¡¡ConsoleApplication£»¡¡in¡¡the¡¡Solution¡¡¡¡

Explorer¡¡and¡¡select¡¡Properties¡£¡¡In¡¡the¡¡Properties¡¡window£»¡¡select¡¡the¡¡References¡¡tab£»¡¡as¡¡shown¡¡¡¡

in¡¡Figure¡¡1¡­9¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡38¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

16¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡ST¡¡E¡¡A¡¡DY¡¡£»¡¡¡¡¡¡G¡¡O¡¡£¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­9¡£¡¡References¡¡used¡¡by¡¡the¡¡Visual¡¡Basic¡¡project¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Calling¡¡Class¡¡Library¡¡Functionality¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡we¡¡need¡¡to¡¡change¡¡ConsoleApplication¡¡so¡¡that¡¡it¡¡calls¡¡the¡¡function¡¡in¡¡ClassLibrary¡£¡¡Modify¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡Module1¡£vb¡¡file¡¡in¡¡ConsoleApplication¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Module¡¡Module1¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Main£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨hello£»¡¡world¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ClassLibrary¡£Class1¡£HelloWorld£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£ReadKey£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Run¡¡ConsoleApplication¡¡by¡¡pressing¡¡Ctrl£«F5¡£¡¡A¡¡mand¡¡prompt¡¡window¡¡should¡¡appear¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡generate¡¡the¡¡¡°hello£»¡¡world¡±¡¡text¡¡twice¡£¡¡The¡¡first¡¡¡°hello£»¡¡world¡±¡¡is¡¡generated¡¡by¡¡the¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨£©¡£¡¡Calling¡¡the¡¡function¡¡ClassLibrary¡£Class1¡£HelloWorld£¨£©¡¡generates¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡second¡¡¡°hello£»¡¡world¡£¡±¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡USING¡¡REFERENCE¡¡SHORTHAND¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ClassLibrary¡£Class1¡£HelloWorld£¨£©¡¡is¡¡the¡¡longhand¡¡way¡¡to¡¡use¡¡a¡¡reference¡£¡¡If¡¡we¡¡were¡¡to¡¡use¡¡long

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡hand¡¡for¡¡the¡¡Console¡£WriteLine£¨£©¡¡call£»¡¡we¡¡would¡¡write¡¡System¡£Console¡£WriteLine£¨£©£»¡¡because¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨£©¡¡method¡¡is¡¡defined¡¡in¡¡the¡¡System¡¡reference¡£¡¡However£»¡¡Visual¡¡Basic¡¡Express¡¡includes¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡¡¡System¡¡reference¡¡by¡¡default£»¡¡so¡¡we¡¡don¡¯t¡¡need¡¡to¡¡do¡¡it¡¡this¡¡way¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡39¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡C¡¡H¡¡AP¡¡TE¡¡R¡¡¡¡¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡R¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡ST¡¡E¡¡AD¡¡Y¡¡£»¡¡¡¡¡¡G¡¡O£¡¡¡17¡¡



¡¡¡¡¡¡To¡¡use¡¡shorthand¡¡for¡¡the¡¡ClassLibrary¡¡call£»¡¡we¡¡would¡¡include¡¡an¡¡¡¡Imports¡¡line¡¡at¡¡the¡¡beginning¡¡of¡¡¡¡

¡¡¡¡¡¡Module1¡£vb¡¡in¡¡ConsoleApplication¡¡and¡¡change¡¡the¡¡call¡¡to¡¡Class1¡¯s¡¡HelloWorld£¨£©¡¡method£º¡¡



¡¡¡¡¡¡Imports¡¡ClassLibrary¡¡

¡¡¡¡¡¡Module¡¡Module1¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sub¡¡Main£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨hello£»¡¡world¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class1¡£HelloWorld£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£ReadKey£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡End¡¡Module¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡But¡¡shorthand¡¡like¡¡this¡¡has¡¡a¡¡downside¡£¡¡What¡¡if¡¡we¡¡had¡¡many¡¡references£»¡¡each¡¡containing¡¡a¡¡class¡¡called¡¡¡¡

¡¡¡¡¡¡Class1£¿¡¡In¡¡this¡¡case£»¡¡Visual¡¡Basic¡¡Express¡¡wouldn¡¯t¡¡know¡¡which¡¡Class1¡¡to¡¡use¡¡without¡¡the¡¡help¡¡of¡¡longhand¡£¡¡¡¡

¡¡¡¡¡¡Granted£»¡¡you¡¡are¡¡not¡¡likely¡¡to¡¡name¡¡multiple¡¡classes¡¡Class1£»¡¡but¡¡even¡¡sensible¡¡names¡¡can¡¡be¡¡duplicated¡¡in¡¡a¡¡¡¡

¡¡¡¡¡¡collection¡¡of¡¡references¡£¡¡And¡¡if¡¡you¡¡are¡¡using¡¡someone¡¡else¡¯s¡¡code¡¡as¡¡a¡¡reference£»¡¡the¡¡possibility¡¡of¡¡duplicate¡¡¡¡

¡¡¡¡¡¡names¡¡bees¡¡higher¡£¡¡Therefore£»¡¡you¡¯re¡¡better¡¡off¡¡using¡¡longhand¡¡in¡¡this¡¡case¡£¡¡



Using¡¡Variables¡¡and¡¡Constants¡¡



One¡¡of¡¡the¡¡core¡¡concepts¡¡in¡¡a¡¡Visual¡¡Basic¡¡program¡¡is¡¡to¡¡use¡¡variables¡£¡¡Think¡¡of¡¡a¡¡variable¡¡as¡¡a¡¡¡¡

block¡¡of¡¡memory¡¡where¡¡you¡¡can¡¡store¡¡data¡¡for¡¡later¡¡use¡£¡¡This¡¡allows¡¡you¡¡to¡¡pass¡¡data¡¡around¡¡¡¡

within¡¡your¡¡program¡¡very¡¡easily¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡In¡¡our¡¡ClassLibrary¡¡project£»¡¡it¡¡would¡¡make¡¡life¡¡easier¡¡if¡¡we¡¡could¡¡define¡¡the¡¡message¡¡to¡¡¡¡

display¡¡at¡¡the¡¡beginning¡¡of¡¡the¡¡method¡£¡¡That¡¡way£»¡¡if¡¡we¡¡decide¡¡to¡¡change¡¡the¡¡message£»¡¡we¡¡can¡¡get¡¡at¡¡¡¡

it¡¡much¡¡more¡¡easily¡£¡¡As¡¡it¡¡stands£»¡¡if¡¡we¡¡were¡¡to¡¡add¡¡more¡¡code¡¡before¡¡the¡¡Console¡£WriteLine£¨£©¡¡call£»¡¡¡¡

we¡¡would¡¡need¡¡to¡¡scroll¡¡through¡¡the¡¡text¡¡to¡¡find¡¡the¡¡message¡¡to¡¡change¡£¡¡A¡¡variable¡¡is¡¡perfect¡¡for¡¡¡¡

this£»¡¡as¡¡we¡¡can¡¡define¡¡some¡¡data¡¡£¨the¡¡message¡¡to¡¡print£©£»¡¡and¡¡then¡¡use¡¡it¡¡later¡¡in¡¡our¡¡program¡£¡¡



Public¡¡Class¡¡Class1¡¡

¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Sub¡¡HelloWorld£¨
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨11£© ²È£¨11£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡