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

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

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


¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡message¡¡As¡¡String¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨message£©¡¡

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡Here£»¡¡we¡¯ve¡¡defined¡¡a¡¡variable¡¡called¡¡message¡¡of¡¡type¡¡¡¡String¡¡£¨a¡¡¡¡String¡¡is¡¡a¡¡length¡¡of¡¡text£©¡£¡¡¡¡

We¡¡can¡¡then¡¡refer¡¡to¡¡the¡¡message¡¡variable¡¡later¡¡when¡¡we¡¡want¡¡to¡¡place¡¡its¡¡contents¡¡into¡¡the¡¡code¡£¡¡¡¡

In¡¡the¡¡example£»¡¡we¡¡place¡¡its¡¡contents¡¡into¡¡the¡¡Console¡£WriteLine£¨£©¡¡call£»¡¡which¡¡works¡¡as¡¡before¡£¡¡¡¡

This¡¡time£»¡¡however£»¡¡we¡¡have¡¡set¡¡the¡¡message¡¡to¡¡display¡¡in¡¡a¡¡separate¡¡statement¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡This¡¡is¡¡very¡¡useful¡¡for¡¡us£»¡¡but¡¡there¡¡is¡¡more¡¡to¡¡variables¡£¡¡They¡¡have¡¡something¡¡that¡¡is¡¡called¡¡¡¡

scope¡£¡¡The¡¡message¡¡variable¡¡has¡¡method¡­level¡¡scope£»¡¡which¡¡means¡¡it¡¡is¡¡available¡¡only¡¡in¡¡the¡¡¡¡

method¡¡in¡¡which¡¡it¡¡is¡¡defined¡£¡¡Consider¡¡this¡¡code£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡40¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡message¡¡As¡¡String¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨message£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Sub¡¡DisplayeMessageText£¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨message£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡DisplayMessageText£¨£©¡¡method¡¡prints¡¡two¡¡lines¡¡of¡¡text¡¡to¡¡tell¡¡us¡¡what¡¡the¡¡message¡¡text¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡should¡¡be¡£¡¡However£»¡¡this¡¡doesn¡¯t¡¡pile£»¡¡because¡¡the¡¡piler¡¡knows¡¡that¡¡the¡¡variable¡¡message¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not¡¡available¡¡to¡¡the¡¡DisplayMessageText£¨£©¡¡method¡¡because¡¡of¡¡its¡¡method¡­level¡¡scope¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡fix¡¡this£»¡¡we¡¡need¡¡to¡¡give¡¡message¡¡class¡­level¡¡scope¡¡by¡¡moving¡¡it¡¡to¡¡the¡¡beginning¡¡of¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡¡definition¡¡£¨as¡¡it¡¡is¡¡used¡¡by¡¡methods¡¡marked¡¡Shared£»¡¡it¡¡must¡¡also¡¡be¡¡Shared£©£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡Class1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Shared¡¡Dim¡¡message¡¡As¡¡String¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨message£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Sub¡¡DisplayeMessageText£¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨message£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡the¡¡variable¡¡message¡¡is¡¡shared¡¡by¡¡all¡¡the¡¡methods¡¡of¡¡Class1¡£¡¡You¡¯ll¡¡learn¡¡much¡¡more¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡about¡¡method¡­level¡¡and¡¡class¡­level¡¡scopes£»¡¡as¡¡well¡¡as¡¡the¡¡Public¡¡and¡¡Shared¡¡keywords£»¡¡throughout¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡book¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Sharing¡¡a¡¡variable¡¡among¡¡methods¡¡of¡¡a¡¡class¡¡can¡¡be¡¡useful£»¡¡but¡¡it¡¯s¡¡sometimes¡¡not¡¡wise¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡do¡¡this¡£¡¡That¡¯s¡¡because¡¡methods¡¡can¡¡change¡¡variables¡¡as¡¡they¡¡carry¡¡out¡¡their¡¡tasks£»¡¡which¡¡can¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡produce¡¡unpredictable¡¡results¡¡further¡¡down¡¡the¡¡line¡£¡¡We¡¡can¡¡lock¡¡the¡¡value¡¡by¡¡using¡¡a¡¡constant¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡instead¡¡of¡¡a¡¡variable¡£¡¡The¡¡Const¡¡keyword¡¡denotes¡¡the¡¡constant£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡Class1¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Const¡¡MESSAGE¡¡As¡¡String¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨MESSAGE£©¡¡

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Sub¡¡DisplayeMessageText£¨£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨MESSAGE£©¡¡

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

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡41¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡Constant¡¡names¡¡are¡¡usually¡¡all¡¡uppercase¡£¡¡The¡¡contents¡¡of¡¡a¡¡constant¡¡cannot¡¡be¡¡changed¡¡¡¡

at¡¡any¡¡point¡£¡¡The¡¡following¡¡would¡¡not¡¡pile£»¡¡for¡¡instance¡£¡¡



Public¡¡Class¡¡Class1¡¡

¡¡¡¡¡¡¡¡Const¡¡MESSAGE¡¡As¡¡String¡¡=¡¡¡¨hello£»¡¡world¡¨¡¡



¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Sub¡¡DisplayeMessageText£¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡MESSAGE¡¡=¡¡¡¨another¡¡text¡¡that¡¡cannot¡¡be¡¡assigned¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨MESSAGE£©¡¡

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

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡you¡¯ve¡¡worked¡¡through¡¡this¡¡chapter¡¯s¡¡examples£»¡¡let¡¯s¡¡talk¡¡a¡¡bit¡¡about¡¡how¡¡your¡¡¡¡

Visual¡¡Basic¡¡code¡¡in¡¡Visual¡¡Basic¡¡Express¡¡actually¡¡turns¡¡into¡¡a¡¡program¡¡that¡¡can¡¡run¡¡on¡¡an¡¡oper

ating¡¡system¡¡like¡¡Windows¡£¡¡



Understanding¡¡How¡¡the¡¡¡¡Framework¡¡Works¡¡



When¡¡you¡¡write¡¡Visual¡¡Basic¡¡source¡¡code£»¡¡you¡¡are¡¡creating¡¡instructions¡¡for¡¡the¡¡program¡¡to¡¡¡¡

follow¡£¡¡The¡¡instructions¡¡are¡¡defined¡¡using¡¡the¡¡Visual¡¡Basic¡¡programming¡¡language£»¡¡which¡¡is¡¡¡¡

useful¡¡for¡¡you£»¡¡but¡¡not¡¡useful¡¡for¡¡the¡¡puter¡£¡¡The¡¡puter¡¡does¡¡not¡¡understand¡¡pieces¡¡of¡¡¡¡

text£»¡¡it¡¡understands¡¡ones¡¡and¡¡zeros¡£¡¡To¡¡feed¡¡instructions¡¡to¡¡the¡¡puter£»¡¡developers¡¡have¡¡¡¡

created¡¡a¡¡higher¡­level¡¡instruction¡¡mechanism¡¡that¡¡converts¡¡your¡¡instructions¡¡into¡¡something¡¡¡¡

that¡¡the¡¡puter¡¡can¡¡understand¡£¡¡The¡¡conversion¡¡utility¡¡is¡¡called¡¡a¡¡piler¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡twist¡¡with¡¡£»¡¡in¡¡contrast¡¡to¡¡traditional¡¡programming¡¡languages¡¡such¡¡as¡¡C£«£«¡¡and¡¡C£»¡¡¡¡

is¡¡that¡¡the¡¡piler¡¡generates¡¡a¡¡binary¡­based¡¡intermediate¡¡language¡¡called¡¡mon¡¡Interme

diate¡¡Language¡¡£¨CIL£©¡£¡¡The¡¡¡¡Framework¡¡then¡¡converts¡¡the¡¡CIL¡¡into¡¡the¡¡binary¡¡instructions¡¡¡¡

required¡¡by¡¡the¡¡puter¡¯s¡¡processor¡£¡¡

¡¡¡¡¡¡¡¡¡¡You¡¡might¡¡think¡¡converting¡¡the¡¡source¡¡code¡¡into¡¡an¡¡intermediate¡¡language¡¡is¡¡inefficient£»¡¡¡¡

but¡¡it¡¡is¡¡a¡¡good¡¡approach¡£¡¡Let¡¯s¡¡use¡¡an¡¡analogy¡£¡¡There¡¡are¡¡dogs¡¡that¡¡learn¡¡quickly¡¡and¡¡those¡¡that¡¡¡¡

take¡¡a¡¡while¡¡to¡¡learn¡£¡¡For¡¡example£»¡¡German¡¡shepherds¡¡tend¡¡to¡¡learn¡¡quickly¡¡and¡¡don¡¯t¡¡require¡¡¡¡

much¡¡repetition¡¡of¡¡lessons¡£¡¡On¡¡the¡¡other¡¡hand£»¡¡bullmastiffs¡¡need¡¡quite¡¡a¡¡bit¡¡of¡¡patience£»¡¡as¡¡they¡¡¡¡

tend¡¡to¡¡be¡¡stubborn¡£¡¡Now¡¡imagine¡¡being¡¡a¡¡trainer¡¡who¡¡has¡¡created¡¡instructions¡¡on¡¡how¡¡to¡¡teach¡¡¡¡

things¡¡specifically¡¡geared¡¡toward¡¡the¡¡bullmastiff¡£¡¡If¡¡those¡¡same¡¡instructions¡¡are¡¡used¡¡on¡¡the¡¡¡¡

German¡¡shepherd£»¡¡you¡¡end¡¡up¡¡boring¡¡the¡¡German¡¡shepherd¡¡and¡¡possibly¡¡failing¡¡to¡¡teach¡¡that¡¡¡¡

dog¡¡what¡¡you¡¡wanted¡¡him¡¡to¡¡learn¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡problem¡¡with¡¡the¡¡instructions¡¡is¡¡that¡¡they¡¡are¡¡specifically¡¡tuned¡¡for¡¡a¡¡single¡¡dog¡£¡¡If¡¡you¡¡¡¡

want¡¡to¡¡teach¡¡both¡¡dogs£»¡¡you¡¡need¡¡two¡¡sets¡¡of¡¡instructions¡£¡¡To¡¡solve¡¡this¡¡problem£»¡¡the¡¡instruc

tions¡¡should¡¡be¡¡general£»¡¡with¡¡added¡¡interpretation¡¡notes¡¡saying¡¡things¡¡like£»¡¡¡°If¡¡dog¡¡is¡¡stubborn£»¡¡¡¡

repeat¡£¡±¡¡

¡¡¡¡¡¡¡¡¡¡Converting¡¡this¡¡into¡¡puter¡­speak£»¡¡the¡¡two¡¡sets¡¡of¡¡instructions¡¡are¡¡for¡¡two¡¡different¡¡¡¡

processors¡¡or¡¡processors¡¡used¡¡in¡¡specific¡¡situations¡£¡¡For¡¡example£»¡¡there¡¡are¡¡server¡¡puters¡¡¡¡

and¡¡client¡¡puters¡£¡¡Each¡¡type¡¡of¡¡puter¡¡has¡¡different¡¡requirements¡£¡¡A¡¡server¡¡puter¡¡¡¡

needs¡¡to¡¡process¡¡data¡¡as¡¡quickly¡¡as¡¡possible£»¡¡whereas¡¡a¡¡client¡¡puter¡¡needs¡¡to¡¡show¡¡data¡¡on¡¡¡¡

the¡¡screen¡¡as¡¡quickly¡¡as¡¡possible¡£¡¡There¡¡are¡¡pilers¡¡for¡¡each¡¡context£»¡¡but¡¡to¡¡have¡¡the¡¡developer¡¡¡¡

create¡¡multiple¡¡distributions¡¡with¡¡different¡¡piler£¨s£©¡¡or¡¡setting£¨s£©¡¡is¡¡inefficient¡£¡¡The¡¡solution¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡42¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡to¡¡create¡¡a¡¡set¡¡of¡¡instructions¡¡that¡¡are¡¡general£»¡¡but¡¡have¡¡associated¡¡interpretation¡¡notes¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Framework¡¡then¡¡applies¡¡these¡¡instructions¡¡using¡¡the¡¡interpretation¡¡notes¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡¡¡Framework¡¡piles¡¡to¡¡instructions¡¡£¨CIL£©¡¡that¡¡are¡¡then¡¡converted¡¡into¡¡processor

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡specific¡¡instructions¡¡using¡¡notes¡¡embedded¡¡in¡¡the¡¡¡¡Framework¡£¡¡The¡¡¡¡architecture¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡illustrated¡¡in¡¡Figure¡¡1¡­10¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡1¡­10¡£¡¡¡¡architecture¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡Figure¡¡1¡­10£»¡¡Visual¡¡Basic¡¡Express¡¡is¡¡responsible¡¡for¡¡converting¡¡the¡¡Visual¡¡Basic¡¡source¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡code¡¡into¡¡a¡¡CIL¡¡package¡£¡¡The¡¡converted¡¡CIL¡¡package¡¡is¡¡a¡¡binary¡¡file¡¡that£»¡¡when¡¡executed£»¡¡requires¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mon¡¡language¡¡runtime¡¡£¨CLR£©¡£¡¡Without¡¡a¡¡CLR¡¡installed¡¡on¡¡your¡¡puter£»¡¡you¡¡cannot¡¡run¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡CIL¡¡package¡£¡¡When¡¡you¡¡installed¡¡Visual¡¡Basic¡¡Express£»¡¡you¡¡installed¡¡the¡¡CLR¡¡in¡¡the¡¡back

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ground¡¡as¡¡a¡¡separate¡¡package¡£¡¡Visual¡¡Basic¡¡Express¡¡is¡¡an¡¡application¡¡that¡¡allows¡¡you¡¡to¡¡develop¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡for¡¡the¡¡CLR£»¡¡but¡¡it¡¡also¡¡uses¡¡the¡¡CLR¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡CLR¡¡has¡¡the¡¡ability¡¡to¡¡transform¡¡your¡¡instructions¡¡in¡¡the¡¡CIL¡¡package¡¡into¡¡something¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡the¡¡operating¡¡system¡¡and¡¡processor¡¡can¡¡understand¡£¡¡If¡¡you¡¡look¡¡at¡¡the¡¡syntax¡¡of¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡patible¡¡languages£»¡¡such¡¡as¡¡Visual¡¡Basic£»¡¡C#£»¡¡and¡¡Eiffel£»¡¡you¡¡will¡¡see¡¡that¡¡they¡¡are¡¡not¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡similar¡£¡¡Yet¡¡the¡¡CLR¡¡can¡¡process¡¡the¡¡CIL¡¡package¡¡generated¡¡by¡¡one¡¡of¡¡those¡¡languages¡¡because¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡¡¡piler£»¡¡regardless¡¡of¡¡programming¡¡language£»¡¡generates¡¡a¡¡set¡¡of¡¡instructions¡¡mon¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡CLR¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡43¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡When¡¡using¡¡the¡¡¡¡Framework£»¡¡you¡¡are¡¡writing¡¡for¡¡the¡¡CLR£»¡¡and¡¡everything¡¡you¡¡do¡¡must¡¡¡¡

be¡¡understood¡¡by¡¡the¡¡CLR¡£¡¡Generally¡¡speaking£»¡¡this¡¡is¡¡not¡¡a¡¡problem¡¡if¡¡you¡¡are¡¡writing¡¡code¡¡in¡¡¡¡

Visual¡¡Basic¡£¡¡The¡¡following¡¡are¡¡some¡¡advantages¡¡of¡¡writing¡¡code¡¡targeted¡¡to¡¡the¡¡CLR£º¡¡



¡¡¡¡¡¡¡¡¡¡Memory¡¡and¡¡garbage¡¡collection£º¡¡Programs¡¡use¡¡resources¡¡such¡¡as¡¡memory£»¡¡files£»¡¡and¡¡so¡¡on¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡In¡¡traditional¡¡programming¡¡languages£»¡¡such¡¡as¡¡C¡¡and¡¡C£«£«£»¡¡you¡¡are¡¡expected¡¡to¡¡open¡¡and¡¡¡¡

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