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

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

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


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

¡¡¡¡¡¡¡¡¡¡¡¡close¡¡a¡¡file£»¡¡and¡¡allocate¡¡and¡¡free¡¡memory¡£¡¡With¡¡£»¡¡you¡¡don¡¯t¡¡need¡¡to¡¡worry¡¡about¡¡closing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡files¡¡or¡¡freeing¡¡memory¡£¡¡The¡¡CLR¡¡knows¡¡when¡¡a¡¡file¡¡or¡¡memory¡¡is¡¡not¡¡in¡¡use¡¡and¡¡will¡¡auto

¡¡¡¡¡¡¡¡¡¡matically¡¡close¡¡the¡¡file¡¡or¡¡free¡¡the¡¡memory¡£¡¡¡¡



¡öNote¡¡¡¡Some¡¡programmers¡¡may¡¡think¡¡that¡¡the¡¡CLR¡¡promotes¡¡sloppy¡¡programming¡¡behavior£»¡¡as¡¡you¡¡don¡¯t¡¡¡¡

need¡¡to¡¡clean¡¡up¡¡after¡¡yourself¡£¡¡However£»¡¡practice¡¡has¡¡shown¡¡that¡¡for¡¡any¡¡plex¡¡application£»¡¡you¡¡will¡¡waste¡¡¡¡

time¡¡and¡¡resources¡¡figuring¡¡out¡¡where¡¡memory¡¡has¡¡not¡¡been¡¡freed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡Custom¡¡optimization£º¡¡Some¡¡programs¡¡need¡¡to¡¡process¡¡large¡¡amounts¡¡of¡¡data£»¡¡such¡¡as¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡from¡¡a¡¡database£»¡¡or¡¡display¡¡a¡¡plex¡¡user¡¡interface¡£¡¡The¡¡performance¡¡focus¡¡for¡¡each¡¡is¡¡on¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡a¡¡different¡¡piece¡¡of¡¡code¡£¡¡The¡¡CLR¡¡has¡¡the¡¡ability¡¡to¡¡optimize¡¡the¡¡CIL¡¡package¡¡and¡¡decide¡¡¡¡

¡¡¡¡¡¡¡¡¡¡how¡¡to¡¡run¡¡it¡¡as¡¡quickly¡¡and¡¡efficiently¡¡as¡¡possible¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡mon¡¡Type¡¡System¡¡£¨CTS£©£º¡¡A¡¡string¡¡in¡¡Visual¡¡Basic¡¡is¡¡a¡¡string¡¡in¡¡C#¡£¡¡This¡¡ensures¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡when¡¡a¡¡CIL¡¡package¡¡generated¡¡by¡¡Visual¡¡Basic¡¡talks¡¡to¡¡a¡¡CIL¡¡package¡¡generated¡¡by¡¡C#£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡there¡¡will¡¡be¡¡no¡¡data¡¡type¡¡misrepresentations¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡Safe¡¡code£º¡¡When¡¡writing¡¡programs¡¡that¡¡interact¡¡with¡¡files¡¡or¡¡memory£»¡¡there¡¡is¡¡a¡¡possibility¡¡¡¡

¡¡¡¡¡¡¡¡¡¡that¡¡a¡¡program¡¡error¡¡can¡¡cause¡¡security¡¡problems¡£¡¡Hackers¡¡will¡¡make¡¡use¡¡of¡¡that¡¡security¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡error¡¡to¡¡run¡¡their¡¡own¡¡programs¡¡and¡¡potentially¡¡cause¡¡financial¡¡disaster¡£¡¡The¡¡CLR¡¡cannot¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡stop¡¡application¡­defined¡¡errors£»¡¡but¡¡it¡¡can¡¡stop¡¡and¡¡rein¡¡in¡¡a¡¡program¡¡that¡¡generates¡¡an¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡error¡¡due¡¡to¡¡incorrect¡¡file¡¡or¡¡memory¡¡access¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡benefit¡¡of¡¡the¡¡CLR¡¡is¡¡allowing¡¡developers¡¡to¡¡focus¡¡on¡¡application¡­related¡¡problems£»¡¡¡¡

because¡¡they¡¡do¡¡not¡¡need¡¡to¡¡worry¡¡about¡¡infrastructure¡­related¡¡problems¡£¡¡With¡¡the¡¡CLR£»¡¡you¡¡¡¡

focus¡¡on¡¡the¡¡application¡¡code¡¡that¡¡reads¡¡and¡¡processes¡¡the¡¡content¡¡of¡¡a¡¡file¡£¡¡Without¡¡the¡¡CLR£»¡¡¡¡

you¡¡would¡¡need¡¡to¡¡also¡¡e¡¡up¡¡with¡¡the¡¡code¡¡that¡¡uses¡¡the¡¡content¡¡in¡¡the¡¡file¡¡and¡¡the¡¡code¡¡that¡¡¡¡

is¡¡responsible¡¡for¡¡opening£»¡¡reading£»¡¡and¡¡closing¡¡the¡¡file¡£¡¡¡¡



The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡



This¡¡chapter¡¡got¡¡you¡¡started¡¡working¡¡with¡¡Visual¡¡Basic¡¡in¡¡an¡¡IDE¡£¡¡Here¡¡are¡¡the¡¡key¡¡points¡¡to¡¡¡¡

remember£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡There¡¡are¡¡three¡¡major¡¡types¡¡of¡¡Visual¡¡Basic¡¡programs£º¡¡Windows¡¡applications£»¡¡console¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡applications£»¡¡and¡¡class¡¡libraries¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡Windows¡¡application¡¡has¡¡a¡¡user¡¡interface¡¡and¡¡behaves¡¡like¡¡other¡¡Windows¡¡applica

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tions¡¡£¨such¡¡as¡¡Notepad¡¡and¡¡Calculator£©¡£¡¡For¡¡Windows¡¡applications£»¡¡you¡¡associate¡¡events¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡actions¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡44¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡console¡¡application¡¡is¡¡simpler¡¡than¡¡a¡¡Windows¡¡application¡¡and¡¡has¡¡no¡¡events¡£¡¡It¡¡is¡¡used¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡process¡¡data¡£¡¡Console¡¡applications¡¡generate¡¡and¡¡accept¡¡data¡¡from¡¡the¡¡mand¡¡line¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡will¡¡want¡¡to¡¡use¡¡an¡¡IDE¡¡to¡¡manage¡¡your¡¡development¡¡cycle¡¡of¡¡coding£»¡¡debugging£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡application¡¡execution¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Among¡¡other¡¡things£»¡¡IDEs¡¡manage¡¡the¡¡organization¡¡of¡¡your¡¡source¡¡code¡¡using¡¡projects¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡solutions¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡In¡¡an¡¡IDE£»¡¡keyboard¡¡shortcuts¡¡make¡¡it¡¡easier¡¡for¡¡you¡¡to¡¡perform¡¡operations¡¡that¡¡you¡¡will¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡do¡¡repeatedly¡£¡¡For¡¡example£»¡¡in¡¡Visual¡¡Basic¡¡Express£»¡¡use¡¡Ctrl£«S¡¡to¡¡save¡¡your¡¡work¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ctrl£«F5¡¡to¡¡run¡¡your¡¡application¡¡without¡¡debugging¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Visual¡¡Basic¡¡Express¡¡projects¡¡contain¡¡plain¡­vanilla¡¡files¡¡and¡¡specialized¡¡groupings¡£¡¡When¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dealing¡¡with¡¡specialized¡¡groupings£»¡¡make¡¡sure¡¡that¡¡you¡¡understand¡¡how¡¡the¡¡groupings¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡function¡¡and¡¡modify¡¡only¡¡those¡¡files¡¡that¡¡you¡¡are¡¡meant¡¡to¡¡modify¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡are¡¡some¡¡questions¡¡related¡¡to¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter¡£¡¡Answering¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡them¡¡will¡¡help¡¡you¡¡to¡¡get¡¡started¡¡developing¡¡your¡¡projects¡¡in¡¡the¡¡IDE¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡answers/solutions¡¡to¡¡the¡¡questions/exercises¡¡included¡¡at¡¡the¡¡end¡¡of¡¡each¡¡chapter¡¡are¡¡available¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡book¡¯s¡¡downloadable¡¡code£»¡¡found¡¡in¡¡the¡¡Source¡¡Code/Download¡¡section¡¡of¡¡the¡¡Apress¡¡web¡¡site¡¡£¨http£º//¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡apress¡££©¡£¡¡Additionally£»¡¡you¡¡can¡¡send¡¡me¡¡an¡¡e¡­mail¡¡message¡¡at¡¡christianhgross@gmail¡£¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡¡¡In¡¡an¡¡IDE£»¡¡solutions¡¡and¡¡projects¡¡are¡¡used¡¡to¡¡classify¡¡related¡¡pieces¡¡of¡¡functionality¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡analogy¡¡I¡¡used¡¡talked¡¡about¡¡cars¡¡and¡¡car¡¡pieces¡£¡¡Would¡¡you¡¡ever¡¡create¡¡a¡¡solution¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡contained¡¡unrelated¡¡pieces¡¡of¡¡functionality£¿¡¡For¡¡example£»¡¡would¡¡you¡¡create¡¡an¡¡airplane¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡solution¡¡that¡¡contained¡¡car¡¡pieces£¿¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡¡¡Projects¡¡are¡¡based¡¡on¡¡templates¡¡created¡¡by¡¡Microsoft¡£¡¡Can¡¡you¡¡think¡¡of¡¡a¡¡situation¡¡where¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡would¡¡create¡¡your¡¡own¡¡template¡¡and¡¡add¡¡it¡¡to¡¡Visual¡¡Basic¡¡Express£¿¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡¡¡In¡¡the¡¡Solution¡¡Explorer£»¡¡each¡¡item¡¡in¡¡the¡¡tree¡¡control¡¡represents¡¡a¡¡single¡¡item¡¡£¨such¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡file£»¡¡user¡¡interface¡¡control£»¡¡and¡¡so¡¡on£©¡£¡¡If¡¡you¡¡were¡¡to¡¡double¡­click¡¡a¡¡¡£vb¡¡file£»¡¡you¡¡would¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡be¡¡manipulating¡¡a¡¡Visual¡¡Basic¡¡file¡¡that¡¡would¡¡contain¡¡Visual¡¡Basic¡¡code¡£¡¡Should¡¡a¡¡single¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡file¡¡reference¡¡a¡¡single¡¡Visual¡¡Basic¡¡class¡¡or¡¡namespace£¿¡¡And¡¡if¡¡not£»¡¡how¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡would¡¡you¡¡organize¡¡your¡¡Visual¡¡Basic¡¡code¡¡with¡¡respect¡¡to¡¡Visual¡¡Basic¡¡files£¿¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡4¡£¡¡¡¡You¡¡have¡¡learned¡¡about¡¡how¡¡a¡¡¡¡application¡¡can¡¡generate¡¡an¡¡executable¡¡file¡£¡¡Let¡¯s¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡say¡¡that¡¡you¡¡take¡¡the¡¡generated¡¡application¡¡and¡¡execute¡¡it¡¡on¡¡another¡¡Windows¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡puter¡£¡¡Will¡¡the¡¡generated¡¡application¡¡run£¿¡¡Let¡¯s¡¡say¡¡that¡¡you¡¡take¡¡the¡¡executable¡¡file¡¡to¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Macintosh¡¡OS¡¡X¡¡or¡¡Linux¡¡puter£»¡¡will¡¡the¡¡application¡¡run£¿¡¡Why¡¡will¡¡it¡¡run¡¡or¡¡not¡¡run£¿¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡45¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



5¡£¡¡¡¡You¡¡are¡¡not¡¡happy¡¡with¡¡the¡¡naming¡¡of¡¡the¡¡element¡¡TextBox1£»¡¡and¡¡want¡¡to¡¡rename¡¡it¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡TxtOutput¡£¡¡How¡¡do¡¡you¡¡go¡¡about¡¡renaming¡¡TextBox1£¿¡¡



6¡£¡¡¡¡ClassLibrary¡¡has¡¡embedded¡¡logic¡¡that¡¡assumes¡¡the¡¡caller¡¡of¡¡the¡¡method¡¡is¡¡a¡¡console¡¡¡¡

¡¡¡¡¡¡¡¡application¡£¡¡Is¡¡it¡¡good¡¡to¡¡assume¡¡a¡¡specific¡¡application¡¡type¡¡or¡¡logic¡¡of¡¡the¡¡caller¡¡in¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡library£¿¡¡If¡¡yes£»¡¡why£¿¡¡If¡¡no£»¡¡why¡¡not£¿¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡46¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡47¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

C¡¡¡¡H¡¡¡¡A¡¡¡¡P¡¡¡¡T¡¡¡¡E¡¡¡¡R¡¡¡¡¡¡¡¡¡¡2¡¡



¡ö¡¡¡ö¡¡¡ö¡¡



Learning¡¡About¡¡¡¡Number¡¡¡¡

and¡¡Value¡¡Types¡¡¡¡



In¡¡the¡¡previous¡¡chapter£»¡¡you¡¡learned¡¡how¡¡to¡¡use¡¡Visual¡¡Basic¡¡Express£»¡¡and¡¡what¡¡¡¡is¡¡in¡¡terms¡¡of¡¡¡¡

the¡¡CIL¡¡and¡¡CLR¡£¡¡In¡¡this¡¡chapter£»¡¡we¡¡are¡¡going¡¡to¡¡roll¡¡up¡¡our¡¡sleeves¡¡and¡¡begin¡¡writing¡¡real¡¡¡¡

Visual¡¡Basic¡¡code¡ªspecifically£»¡¡a¡¡calculator¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡A¡¡calculator¡¡is¡¡an¡¡ideal¡¡example¡¡to¡¡start¡¡with£»¡¡because¡¡it¡¡allows¡¡you¡¡to¡¡focus¡¡on¡¡the¡¡applica

tion¡¡without¡¡having¡¡to¡¡deal¡¡with¡¡all¡¡the¡¡nasty¡¡details¡¡that¡¡are¡¡normally¡¡associated¡¡with¡¡programs¡£¡¡¡¡

In¡¡a¡¡programming¡¡language¡¡like¡¡Visual¡¡Basic£»¡¡adding¡¡two¡¡numbers¡¡is¡¡trivial¡£¡¡What¡¡is¡¡not¡¡trivial¡¡¡¡

is¡¡how¡¡to¡¡put¡¡the¡¡operation¡¡of¡¡adding¡¡two¡¡numbers¡¡into¡¡a¡¡program¡£¡¡

¡¡¡¡¡¡¡¡¡¡This¡¡chapter¡¡focuses¡¡on¡¡the¡¡mechanics¡¡of¡¡writing¡¡a¡¡program¡¡in¡¡Visual¡¡Basic¡ªtaking¡¡an¡¡¡¡

idea¡¡and¡¡converting¡¡it¡¡into¡¡a¡¡Visual¡¡Basic¡¡program¡¡that¡¡can¡¡execute¡¡your¡¡intentions¡£¡¡You¡¯ll¡¡learn¡¡¡¡

how¡¡to¡¡organize¡¡your¡¡development¡¡and¡¡implement¡¡a¡¡Visual¡¡Basic¡¡class¡¡library£»¡¡as¡¡well¡¡as¡¡how¡¡¡¡

the¡¡¡¡CLR¡¡manages¡¡number¡¡types¡£¡¡



Focusing¡¡and¡¡Organizing¡¡Your¡¡Development¡¡



When¡¡you¡¡develop¡¡software£»¡¡you¡¡will¡¡split¡¡your¡¡work¡¡into¡¡two¡¡main¡¡tasks£º¡¡organizing¡¡and¡¡imple

menting¡£¡¡Organizing¡¡your¡¡development¡¡involves¡¡figuring¡¡out¡¡what¡¡features¡¡and¡¡libraries¡¡you¡¡¡¡

are¡¡going¡¡to¡¡define£»¡¡how¡¡many¡¡people¡¡are¡¡going¡¡to¡¡be¡¡developing¡¡the¡¡features£»¡¡and¡¡so¡¡on¡£¡¡

¡¡¡¡¡¡¡¡¡¡Organizing¡¡your¡¡development¡¡is¡¡one¡¡of¡¡the¡¡most¡¡important¡¡tasks¡¡when¡¡writing¡¡code£»¡¡and¡¡¡¡

it¡¡is¡¡also¡¡typically¡¡the¡¡most¡¡confusing¡¡for¡¡new¡¡developers¡£¡¡Professional¡¡developers¡¡seem¡¡to¡¡¡¡

organize¡¡their¡¡work¡¡instinctively£»¡¡but¡¡it¡¡only¡¡appears¡¡that¡¡way¡¡because¡¡they¡¡have¡¡done¡¡it¡¡so¡¡¡¡

many¡¡times¡¡that¡¡the¡¡process¡¡has¡¡bee¡¡automatic¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡When¡¡developers¡¡are¡¡tasked¡¡with¡¡creating¡¡a¡¡program£»¡¡they¡¡are¡¡asked¡¡to¡¡write¡¡software¡¡that¡¡¡¡

implements¡¡a¡¡set¡¡of¡¡features¡£¡¡Features¡¡could¡¡include¡¡calculating¡¡daily¡¡interest¡¡payments£»¡¡auto

matically¡¡generating¡¡letters¡¡indicating¡¡the¡¡acceptance¡¡or¡¡rejection¡¡of¡¡a¡¡loan£»¡¡and¡¡so¡¡on¡£¡¡A¡¡feature¡¡¡¡

always¡¡relates¡¡to¡¡performing¡¡some¡¡task¡¡that¡¡is¡¡determined¡¡by¡¡some¡¡process¡£¡¡You¡¡could¡¡say¡¡that¡¡¡¡

feature¡¡implementation¡¡is¡¡the¡¡direct¡¡implementation¡¡of¡¡a¡¡task¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡25¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡48¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

26¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡defining¡¡the¡¡features£»¡¡two¡¡major¡¡steps¡¡are¡¡involved£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Gain¡¡an¡¡understanding¡¡of¡¡the¡¡features¡£¡¡You¡¡can¡¯t¡¡implement¡¡something¡¡that¡¡you¡¡don¡¯t¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡understand¡£¡¡To¡¡be¡¡able¡¡to¡¡write¡¡the¡¡source¡¡code¡¡for¡¡a¡¡feature£»¡¡you¡¡need¡¡to¡¡know¡¡the¡¡whys¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡whats¡¡of¡¡a¡¡feature¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Describe¡¡the¡¡features¡¡using¡¡structured¡¡design¡¡methods¡£¡¡Simply¡¡organizing¡¡your¡¡thoughts¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡may¡¡be¡¡enough¡¡if¡¡you¡¡are¡¡the¡¡only¡¡person¡¡working¡¡on¡¡a¡¡program£»¡¡however£»¡¡more¡¡often¡¡than¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡not£»¡¡you¡¡will¡¡be¡¡part¡¡of¡¡a¡¡team¡£¡¡You¡¡need¡¡to¡¡use¡¡a¡¡structured¡¡design¡¡method¡¡so¡¡that¡¡you¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡your¡¡team¡¡members¡¡can¡¡municate¡¡the¡¡thoughts¡¡related¡¡to¡¡program¡¡development¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡One¡¡mon¡¡structured¡¡design¡¡method¡¡is¡¡the¡¡Unified¡¡Modeling¡¡Language¡¡£¨UML£©¡£¡¡UML¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡used¡¡to¡¡organize¡¡the¡¡features¡¡into¡¡units¡¡that¡¡correspond¡¡to¡¡programming¡¡language¡¡constructs£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡such¡¡as¡¡classes¡£¡¡Think¡¡of¡¡UML¡¡as¡¡software¡¡developer¡­specific¡¡lingo¡¡used¡¡to¡¡describe¡¡the¡¡various¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡aspects¡¡of¡¡a¡¡programming¡¡environment¡¡at¡¡a¡¡higher¡¡level¡¡of¡¡abstraction¡£¡¡UML¡¡allows¡¡you¡¡to¡¡get¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡an¡¡overall¡¡understanding¡¡of¡¡the¡¡architecture¡¡without¡¡having¡¡to¡¡read¡¡the¡¡source¡¡code¡£¡¡Think¡¡of¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡UML¡¡as¡¡the¡¡structured¡¡doodle¡¡on¡¡the¡¡napkin¡¡of¡¡software¡¡programming¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Along¡¡with¡¡UML£»¡¡there¡¡are¡¡other¡¡ways¡¡of¡¡structuring¡¡your¡¡development¡¡process¡£¡¡For¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡another¡¡technique¡¡is¡¡called¡¡agile¡¡software¡¡development¡£¡¡The¡¡idea¡¡with¡¡agile¡¡software¡¡develop

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ment¡¡is¡¡to¡¡use¡¡a¡¡whiteboard¡¡and¡¡develop¡¡your¡¡own¡¡structured¡¡munication¡¡mechanism¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡choice¡¡of¡¡UML£»¡¡agile¡¡software¡¡development£»¡¡or¡¡another¡¡structured¡¡design¡¡method¡¡is¡¡¡¡

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