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

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

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


¡¡¡¡¡¡¡¡¡¡We¡¡could¡¡use¡¡one¡¡of¡¡three¡¡types¡¡to¡¡declare¡¡the¡¡Add£¨£©¡¡method£º¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Long£º¡¡Solves¡¡the¡¡problem¡¡of¡¡adding¡¡two¡¡very¡¡large¡¡numbers¡¡like¡¡2¡¡billion£»¡¡but¡¡has¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡problem¡¡that¡¡you¡¡cannot¡¡add¡¡fractional¡¡numbers¡¡like¡¡1¡£5¡¡plus¡¡1¡£5¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡Double£º¡¡Solves¡¡the¡¡problem¡¡of¡¡adding¡¡two¡¡very¡¡large¡¡or¡¡small¡¡numbers£»¡¡and¡¡can¡¡be¡¡used¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡add¡¡fractional¡¡numbers¡£¡¡Generally¡¡speaking£»¡¡Double¡¡is¡¡a¡¡good¡¡choice£»¡¡but¡¡can¡¡suffer¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡significance¡¡problems¡¡if¡¡a¡¡very¡¡large¡¡number¡¡is¡¡manipulated¡¡by¡¡a¡¡very¡¡small¡¡number¡£¡¡



¡¡¡¡¡¡¡¡¡¡o¡¡Decimal£º¡¡A¡¡generally¡¡good¡¡approach¡¡and¡¡suitable¡¡for¡¡all¡¡types¡¡of¡¡precision£»¡¡but¡¡also¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡slowest¡¡when¡¡adding£»¡¡subtracting£»¡¡or¡¡performing¡¡other¡¡mathematical¡¡operations¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡simplest¡¡all¡­around¡¡numeric¡¡data¡¡type¡¡to¡¡use¡¡is¡¡Double£»¡¡as¡¡it¡¡provides¡¡good¡¡precision¡¡¡¡

and¡¡is¡¡relatively¡¡fast¡£¡¡The¡¡plete¡¡implementation¡¡of¡¡the¡¡calculator¡¡is¡¡as¡¡follows£º¡¡



Public¡¡Class¡¡Operations¡¡

¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Add£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡

Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡£«¡¡number2¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡



¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Divide£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡

Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡/¡¡number2¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡



¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Multiply£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡

Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡*¡¡number2¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡



¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Subtract£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡

Double£©¡¡As¡¡Double¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡number2¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡

End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡four¡¡operations¡¡are¡¡methods¡¡with¡¡different¡¡identifiers£»¡¡but¡¡identical¡¡method¡¡signa

tures£»¡¡making¡¡it¡¡easy¡¡to¡¡remember¡¡how¡¡to¡¡use¡¡each¡¡method¡£¡¡Each¡¡of¡¡the¡¡operations¡¡would¡¡have¡¡¡¡

an¡¡appropriate¡¡set¡¡of¡¡tests¡¡verifying¡¡the¡¡correctness¡¡of¡¡the¡¡implementation¡£¡¡The¡¡tests¡¡are¡¡not¡¡¡¡

reproduced¡¡here£»¡¡but¡¡they¡¡are¡¡implemented¡¡in¡¡the¡¡sample¡¡source¡¡code¡£¡¡I¡¡advise¡¡you¡¡to¡¡take¡¡a¡¡¡¡

quick¡¡look¡¡at¡¡the¡¡tests¡¡to¡¡make¡¡sure¡¡you¡¡understand¡¡the¡¡individual¡¡pieces¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡70¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

48¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡



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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡developing¡¡a¡¡class¡¡library¡¡that¡¡is¡¡used¡¡to¡¡perform¡¡some¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡calculations¡£¡¡The¡¡following¡¡are¡¡the¡¡key¡¡points¡¡to¡¡remember£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Organization¡¡of¡¡your¡¡thoughts£»¡¡projects£»¡¡and¡¡features¡¡makes¡¡all¡¡the¡¡difference¡¡when¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡writing¡¡software¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡writing¡¡software£»¡¡stay¡¡focused¡£¡¡It¡¡is¡¡very¡¡easy¡¡to¡¡drift¡¡around¡¡in¡¡software¡¡development£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡because¡¡software¡¡lets¡¡you¡¡stray¡¡easily¡£¡¡A¡¡successful¡¡developer¡¡will¡¡always¡¡be¡¡organized¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡focused¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Software¡¡is¡¡designed¡¡using¡¡an¡¡architecture¡¡that¡¡could¡¡be¡¡implemented¡¡top¡­down¡¡or¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bottom¡­up¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Within¡¡an¡¡architecture£»¡¡individual¡¡pieces¡¡are¡¡called¡¡ponents£»¡¡and¡¡they¡¡fit¡¡together¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡create¡¡a¡¡plete¡¡application¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡write¡¡tests¡¡because¡¡you¡¡cannot¡¡verify¡¡the¡¡functionality¡¡of¡¡a¡¡ponent¡¡based¡¡on¡¡its¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡identifier£»¡¡parameters£»¡¡or¡¡return¡¡value¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡implementing¡¡ponents£»¡¡you¡¡develop¡¡tests¡¡before£»¡¡during£»¡¡and¡¡after¡¡writing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡source¡¡code¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡test¡¡is¡¡a¡¡piece¡¡of¡¡source¡¡code¡¡that¡¡calls¡¡a¡¡ponent¡¡using¡¡targeted¡¡input¡¡data£»¡¡and¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡results¡¡from¡¡the¡¡ponent¡¡are¡¡verified¡¡with¡¡targeted¡¡responses¡£¡¡If¡¡the¡¡results¡¡do¡¡not¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡match¡¡the¡¡targeted¡¡responses£»¡¡the¡¡ponent¡¡has¡¡failed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡CLR¡¡offers¡¡many¡¡different¡¡data¡¡types£»¡¡with¡¡the¡¡major¡¡distinction¡¡being¡¡between¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡and¡¡reference¡¡types¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡CLR¡¡has¡¡many¡¡different¡¡number¡¡types£»¡¡but¡¡all¡¡number¡¡types¡¡are¡¡value¡¡types¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Numbers¡¡can¡¡overflow¡¡or¡¡underflow¡£¡¡You¡¡should¡¡activate¡¡a¡¡piler¡¡setting¡¡to¡¡make¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sure¡¡that¡¡the¡¡CLR¡¡will¡¡catch¡¡those¡¡situations¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡deciding¡¡on¡¡a¡¡specific¡¡number¡¡type£»¡¡a¡¡large¡¡part¡¡of¡¡the¡¡decision¡¡is¡¡based¡¡on¡¡how¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡much¡¡precision¡¡is¡¡desired¡£¡¡



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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡are¡¡some¡¡things¡¡to¡¡consider¡¡related¡¡to¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡When¡¡you¡¡write¡¡code£»¡¡how¡¡should¡¡you¡¡organize¡¡your¡¡code£¿¡¡For¡¡example£»¡¡do¡¡you¡¡enforce¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡certain¡¡naming¡¡conventions¡¡for¡¡your¡¡classes£¿¡¡Do¡¡you¡¡enforce¡¡the¡¡use¡¡of¡¡code¡¡ments£¿¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡In¡¡the¡¡development¡¡munity£»¡¡there¡¡is¡¡a¡¡discussion¡¡of¡¡whether¡¡organization¡¡of¡¡your¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡software¡¡should¡¡involve¡¡formal¡¡structures¡¡or¡¡should¡¡be¡¡ad¡¡hoc¡£¡¡Think¡¡about¡¡how¡¡software¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡should¡¡be¡¡organized¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡In¡¡general£»¡¡how¡¡would¡¡you¡¡test¡¡whether¡¡or¡¡not¡¡a¡¡ponent¡¡that¡¡uses¡¡a¡¡database¡¡worked¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡properly£¿¡¡Outline¡¡the¡¡process¡¡with¡¡bulleted¡¡points¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡71¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡49¡¡



4¡£¡¡¡¡In¡¡general£»¡¡how¡¡would¡¡you¡¡test¡¡the¡¡correctness¡¡of¡¡writing¡¡data¡¡to¡¡a¡¡file£¿¡¡To¡¡help¡¡under

¡¡¡¡¡¡¡¡stand¡¡the¡¡nature¡¡of¡¡the¡¡problem£»¡¡how¡¡do¡¡you¡¡know¡¡that¡¡an¡¡operating¡¡system¡¡manipulates¡¡¡¡

¡¡¡¡¡¡¡¡files¡¡properly£¿¡¡



5¡£¡¡¡¡If¡¡the¡¡CLR¡¡did¡¡not¡¡provide¡¡for¡¡a¡¡mechanism¡¡to¡¡catch¡¡overflow¡¡and¡¡underflow¡¡conditions£»¡¡¡¡

¡¡¡¡¡¡¡¡how¡¡would¡¡you¡¡ensure¡¡that¡¡overflow¡¡and¡¡underflow¡¡didn¡¯t¡¡happen£¿¡¡



6¡£¡¡¡¡For¡¡a¡¡Pentium¡¡CPU¡¡£¨32¡¡bits£©£»¡¡which¡¡number¡¡type¡¡would¡¡result¡¡in¡¡the¡¡fastest¡¡calculations£¿¡¡



7¡£¡¡¡¡In¡¡this¡¡chapter¡¯s¡¡example£»¡¡the¡¡class¡¡Operations¡¡is¡¡designed¡¡to¡¡perform¡¡arithmetic¡¡using¡¡¡¡

¡¡¡¡¡¡¡¡the¡¡Double¡¡type¡£¡¡How¡¡would¡¡you¡¡change¡¡this¡¡so¡¡that¡¡the¡¡calculations¡¡are¡¡generic¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡don¡¯t¡¡rely¡¡on¡¡the¡¡Double¡¡type£¿¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡72¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡73¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



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



Learning¡¡About¡¡String¡¡¡¡

¡¡Manipulations¡¡¡¡



In¡¡the¡¡previous¡¡chapter£»¡¡you¡¡learned¡¡the¡¡basics¡¡of¡¡how¡¡data¡¡is¡¡stored¡¡and¡¡managed¡¡by¡¡£»¡¡¡¡

including¡¡the¡¡difference¡¡between¡¡value¡¡and¡¡reference¡¡types¡£¡¡¡¡has¡¡three¡¡major¡¡data¡¡types£º¡¡¡¡

number¡­related£»¡¡custom¡­defined£»¡¡and¡¡String¡£¡¡The¡¡previous¡¡chapter¡¡focused¡¡on¡¡the¡¡number

related¡¡types¡£¡¡This¡¡chapter¡¡will¡¡focus¡¡on¡¡the¡¡String¡¡type¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡As¡¡you¡¯ll¡¡learn¡¡in¡¡this¡¡chapter£»¡¡the¡¡String¡¡type¡¡has¡¡some¡¡special¡¡characteristics¡£¡¡If¡¡you¡¡were¡¡¡¡

to¡¡look¡¡at¡¡the¡¡bits¡¡and¡¡bytes¡¡of¡¡the¡¡String¡¡type£»¡¡you¡¡would¡¡not¡¡realize¡¡that¡¡they¡¡were¡¡letters¡£¡¡In¡¡¡¡

an¡¡abstract¡¡description£»¡¡a¡¡String¡¡type¡¡is¡¡a¡¡number¡¡type¡¡with¡¡a¡¡special¡¡grammar¡£¡¡Since¡¡a¡¡puter¡¡¡¡

understands¡¡only¡¡numbers£»¡¡it¡¡uses¡¡lookup¡¡tables¡¡that¡¡map¡¡a¡¡set¡¡of¡¡letters¡¡to¡¡a¡¡set¡¡of¡¡numbers¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡example¡¡in¡¡this¡¡chapter¡¡is¡¡a¡¡multilingual¡¡translation¡¡program¡£¡¡The¡¡translation¡¡program¡¡¡¡

will¡¡not¡¡be¡¡sophisticated£»¡¡nor¡¡will¡¡it¡¡be¡¡capable¡¡of¡¡much¡£¡¡However£»¡¡it¡¡will¡¡illustrate¡¡many¡¡of¡¡the¡¡¡¡

issues¡¡that¡¡you¡¡will¡¡be¡¡confronted¡¡with¡¡when¡¡working¡¡with¡¡strings¡£¡¡



Organizing¡¡the¡¡Translation¡¡Application¡¡



As¡¡emphasized¡¡in¡¡the¡¡previous¡¡chapter£»¡¡the¡¡first¡¡step¡¡in¡¡developing¡¡an¡¡application¡¡is¡¡to¡¡get¡¡¡¡

organized¡£¡¡We¡¡need¡¡to¡¡understand¡¡and¡¡define¡¡the¡¡features¡¡of¡¡the¡¡sample¡¡application¡¡we¡¡are¡¡¡¡

going¡¡to¡¡develop¡£¡¡The¡¡multilingual¡¡translation¡¡program¡¡will¡¡implement¡¡the¡¡following¡¡features£º¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Translate¡¡greetings¡¡into¡¡three¡¡different¡¡languages£º¡¡French£»¡¡German£»¡¡and¡¡English¡£¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Convert¡¡numbers¡¡into¡¡the¡¡three¡¡different¡¡languages¡£¡¡



¡¡¡¡¡¡¡¡o¡¡¡¡Convert¡¡a¡¡date¡¡into¡¡the¡¡three¡¡different¡¡languages¡£¡¡



¡¡¡¡¡¡¡¡¡¡From¡¡a¡¡feature¡¡perspective£»¡¡the¡¡first¡¡feature¡¡is¡¡logical£»¡¡but¡¡the¡¡second¡¡and¡¡third¡¡features¡¡are¡¡¡¡

not¡¡as¡¡obvious¡£¡¡We¡¡generally¡¡think¡¡of¡¡translation¡¡as¡¡translating¡¡one¡¡word¡¡to¡¡another¡¡word£¨s£©¡£¡¡¡¡

Yet£»¡¡languages¡¡also¡¡can¡¡represent¡¡numbers¡¡and¡¡dates¡¡in¡¡different¡¡ways¡£¡¡Translation¡¡will¡¡mean¡¡¡¡

two¡¡things£º¡¡translate¡¡a¡¡word¡¡from¡¡one¡¡language¡¡to¡¡another£»¡¡and¡¡translate¡¡a¡¡number¡¡or¡¡date¡¡¡¡

from¡¡one¡¡language¡¡to¡¡another¡£¡¡

¡¡¡¡¡¡¡¡¡¡As¡¡in¡¡Chapter¡¡2£»¡¡we¡¯ll¡¡create¡¡the¡¡solution¡¡as¡¡ponents¡¡with¡¡three¡¡pieces£º¡¡a¡¡Windows¡¡¡¡

application£»¡¡a¡¡testing¡¡console¡¡application£»¡¡and¡¡a¡¡class¡¡library¡£¡¡After¡¡you¡¡have¡¡created¡¡each¡¡of¡¡the¡¡¡¡

projects£»¡¡your¡¡workspace¡¡should¡¡look¡¡like¡¡Figure¡¡3¡­1¡£¡¡Remember¡¡to¡¡add¡¡a¡¡reference¡¡to¡¡the¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡51¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡74¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

52¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡P¡¡U¡¡L¡¡AT¡¡IO¡¡N¡¡S¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡LanguageTranslator¡¡class¡¡library¡¡£¨right¡­click¡¡TestLanguageTranslator¡¡and¡¡choose¡¡Add¡¡Reference¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Projects¡¡¡¡LanguageTranslator£©¡£¡¡Also¡¡remember¡¡to¡¡set¡¡TestLanguageTranslator¡¡as¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡startup¡¡project¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­1¡£¡¡Structure¡¡of¡¡projects¡¡for¡¡the¡¡translation¡¡application¡¡in¡¡Visual¡¡Basic¡¡Express¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Solution¡¡Explorer¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Building¡¡the¡¡Translator¡¡Application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡translation¡¡application£»¡¡like¡¡the¡¡calculator¡¡application¡¡example¡¡in¡¡the¡¡previous¡¡chapter£»¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡built¡¡in¡¡pieces£º¡¡the¡¡class¡¡library¡¡that¡¡performs¡¡translations¡¡based¡¡on¡¡data¡¡delivered¡¡by¡¡the¡¡user¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡interface£»¡¡the¡¡tests£»¡¡and¡¡the¡¡user¡¡interface¡£¡¡The¡¡individual¡¡pieces¡¡are¡¡ponents¡¡that¡¡can¡¡be¡¡fit¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡together¡¡like¡¡a¡¡jigsaw¡¡puzzle¡¡to¡¡create¡¡an¡¡application¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡ponents¡¡are¡¡a¡¡core¡¡part¡¡of¡¡your¡¡development¡¡toolbox¡£¡¡As¡¡you¡¡will¡¡see¡¡throughout¡¡the¡¡book£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ponents¡¡allow¡¡you¡¡to¡¡reuse¡¡and¡¡modularize¡¡functionality¡£¡¡ponents¡¡result¡¡in¡¡applications¡¡that¡¡are¡¡main

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡tainable¡¡and¡¡extendable¡£¡¡Of¡¡course£»¡¡there¡¡are¡¡limits£»¡¡and¡¡the¡¡advantages¡¡are¡¡not¡¡automatic¡£¡¡You¡¡will¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡properly¡¡design¡¡your¡¡application¡¡to¡¡benefit¡¡from¡¡using¡¡ponents¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Creating¡¡the¡¡Translator¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡working¡¡with¡¡Visual¡¡Basic¡¡Express£»¡¡or¡¡one¡¡of¡¡the¡¡other¡¡Visual¡¡Studio¡¡products£»¡¡using¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡default¡¡templates¡¡for¡¡creating¡¡a¡¡class¡¡library¡¡results¡¡in¡¡the¡¡creation¡¡of¡¡a¡¡file¡¡named¡¡Class1¡£vb¡£¡¡It¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡good¡¡that¡¡a¡¡default¡¡file¡¡is¡¡created¡¡for¡¡a¡¡class¡¡library£»¡¡but¡¡the¡¡identifier¡¡Class1¡£vb¡¡does¡¡not¡¡imply¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡much¡£¡¡Therefore£»¡¡you¡¡should¡¡go¡¡ahead¡¡and¡¡delete¡¡that¡¡file¡¡from¡¡the¡¡project¡¡£¨simply¡¡renaming¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡file¡¡does¡¡not¡¡rename¡¡the¡¡class¡¡within¡¡it£©¡£¡¡In¡¡its¡¡place£»¡¡create¡¡the¡¡Translator¡¡class£»¡¡as¡¡follows£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡Right¡­click¡¡the¡¡¡¡LanguageTranslator¡¡project¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡Click¡¡Add¡¡¡¡New¡¡Item¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡Select¡¡Class¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡75¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡PU¡¡L¡¡A¡¡TI¡¡O¡¡N¡¡S¡¡¡¡53¡¡



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