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

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

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





Quoting¡¡Strings¡¡



Along¡¡with¡¡strings£»¡¡Visual¡¡Basic¡¡has¡¡the¡¡Char¡¡type¡£¡¡A¡¡Char¡¡can¡¡be¡¡described¡¡as¡¡a¡¡single¡¡letter¡¡of¡¡a¡¡¡¡

sentence¡£¡¡However£»¡¡it¡¡would¡¡be¡¡more¡¡accurate¡¡to¡¡say¡¡that¡¡it¡¡is¡¡a¡¡single¡¡character¡£¡¡You¡¡can¡¡assign¡¡¡¡

a¡¡string¡¡to¡¡a¡¡Char¡¡type£»¡¡as¡¡long¡¡as¡¡Option¡¡Strict¡¡is¡¡Off¡¡£¨which¡¡it¡¡is¡¡by¡¡default£©¡£¡¡For¡¡example£»¡¡suppose¡¡¡¡

you¡¡wrote¡¡the¡¡following¡¡code¡¡to¡¡assign¡¡a¡¡string¡¡to¡¡the¡¡variable¡¡val¡£¡¡



¡¡'¡¡The¡¡Option¡¡Strict¡¡declaration¡¡must¡¡e¡¡right¡¡at¡¡the¡¡top¡¡of¡¡your¡¡code¡¡

Option¡¡Strict¡¡Off¡¡

¡¡¡£¡¡¡£¡¡¡£¡¡

Dim¡¡val¡¡As¡¡Char¡¡

val¡¡=¡¡¡¨hello¡¨¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡example¡¡piles£»¡¡but¡¡you¡¡will¡¡not¡¡get¡¡what¡¡you¡¡want¡£¡¡Because¡¡Option¡¡Strict¡¡is¡¡Off£»¡¡¡¡

the¡¡string¡¡is¡¡converted¡¡to¡¡a¡¡character¡£¡¡In¡¡this¡¡conversion£»¡¡data¡¡is¡¡lost¡ªspecifically£»¡¡the¡¡characters¡¡¡¡

ello¡¡are¡¡lost¡£¡¡The¡¡value¡¡stored¡¡in¡¡the¡¡variable¡¡val¡¡is¡¡the¡¡single¡¡letter¡¡h¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡If¡¡Option¡¡Strict¡¡were¡¡On£»¡¡the¡¡example¡¡would¡¡not¡¡pile¡£¡¡When¡¡Option¡¡Strict¡¡is¡¡On£»¡¡the¡¡¡¡

piler¡¡does¡¡not¡¡do¡¡conversions¡¡where¡¡data¡¡might¡¡be¡¡lost¡£¡¡If¡¡you¡¡have¡¡code¡¡that¡¡does¡¡attempt¡¡¡¡

a¡¡conversion£»¡¡an¡¡error¡¡will¡¡be¡¡flagged¡¡by¡¡the¡¡piler¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡really¡¡wanted¡¡to¡¡store¡¡the¡¡single¡¡letter¡¡h¡¡in¡¡the¡¡variable¡¡val£»¡¡you¡¡would¡¡need¡¡to¡¡explicitly¡¡¡¡

define¡¡the¡¡character¡¡to¡¡be¡¡assigned¡¡to¡¡the¡¡variable£»¡¡as¡¡follows£º¡¡



Option¡¡Strict¡¡On¡¡

¡¡¡£¡¡¡£¡¡¡£¡¡

Dim¡¡val¡¡As¡¡Char¡¡

val¡¡=¡¡¡¨h¡¨c¡¡



¡¡¡¡¡¡¡¡¡¡To¡¡define¡¡a¡¡single¡­character¡¡string£»¡¡you¡¡enclose¡¡that¡¡character¡¡in¡¡double¡¡quotation¡¡marks£»¡¡¡¡

followed¡¡by¡¡a¡¡lowercase¡¡c¡¡to¡¡indicate¡¡that¡¡the¡¡single¡­character¡¡string¡¡is¡¡a¡¡character¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡88¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡VISUAL¡¡BASIC¡¡STRICT¡¡AND¡¡EXPLICIT¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Programming¡¡languages¡¡have¡¡two¡¡distinct¡¡flavors£º¡¡static¡¡typed¡¡and¡¡dynamic¡¡typed¡£¡¡Do¡¡not¡¡get¡¡these¡¡two¡¡terms¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡confused¡¡with¡¡the¡¡terms¡¡strongly¡¡typed¡¡and¡¡¡¡weakly¡¡typed¡£¡¡Those¡¡two¡¡sets¡¡of¡¡terms¡¡are¡¡orthogonal¡¡to¡¡each¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡other¡£¡¡A¡¡language¡¡can¡¡be¡¡dynamic¡¡typed¡¡and¡¡strongly¡¡typed¡¡at¡¡the¡¡same¡¡time¡£¡¡For¡¡example£»¡¡the¡¡following¡¡code¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡strongly¡¡and¡¡dynamic¡¡typed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡a¡¡=¡¡10¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡type¡¡is¡¡dynamic¡¡because¡¡I¡¡have¡¡not¡¡declared¡¡the¡¡variable¡¡to¡¡be¡¡of¡¡any¡¡type¡£¡¡It¡¡is¡¡strongly¡¡typed¡¡because¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡when¡¡a¡¡is¡¡assigned¡¡to¡¡a¡¡value¡¡of¡¡10£»¡¡it¡¡is¡¡defined¡¡to¡¡be¡¡an¡¡Integer¡£¡¡A¡¡strongly¡¡and¡¡dynamic¡¡typed¡¡language¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡means¡¡that¡¡variables¡¡can¡¡be¡¡any¡¡type£»¡¡but¡¡once¡¡they¡¡are¡¡assigned£»¡¡their¡¡type¡¡cannot¡¡be¡¡changed¡£¡¡Thus£»¡¡you¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cannot¡¡convert¡¡an¡¡integer¡¡to¡¡a¡¡string¡¡or¡¡a¡¡string¡¡to¡¡an¡¡integer¡¡without¡¡some¡¡type¡¡of¡¡failure¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡code¡¡is¡¡weakly¡¡and¡¡static¡¡typed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡val¡¡As¡¡Char¡¡=¡¡¡¨hello¡¨¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Here£»¡¡I¡¡explicitly¡¡say¡¡that¡¡val¡¡is¡¡a¡¡Char£»¡¡and¡¡I¡¯ve¡¡assigned¡¡to¡¡it¡¡a¡¡string¡£¡¡However£»¡¡because¡¡of¡¡weak¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡typing£»¡¡a¡¡strong¡­armed¡¡conversion¡¡of¡¡the¡¡string¡¡to¡¡a¡¡Char¡¡is¡¡made¡£¡¡Think¡¡of¡¡it¡¡as¡¡fitting¡¡a¡¡square¡¡peg¡¡into¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡round¡¡hole¡£¡¡If¡¡the¡¡square¡¡peg¡¡has¡¡a¡¡diagonal¡¡length¡¡less¡¡than¡¡the¡¡diameter¡¡of¡¡the¡¡hole£»¡¡the¡¡process¡¡works¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡without¡¡much¡¡effort¡£¡¡But¡¡if¡¡the¡¡square¡¡peg¡¯s¡¡length¡¡is¡¡the¡¡same¡¡as¡¡the¡¡diameter¡¡of¡¡the¡¡hole£»¡¡you¡¡will¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡use¡¡brute¡¡force¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡allows¡¡you¡¡to¡¡write¡¡all¡¡types¡¡of¡¡code£»¡¡and¡¡the¡¡flags¡¡Option¡¡Strict¡¡and¡¡Option¡¡Explicit¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡relate¡¡to¡¡what¡¡kind¡¡of¡¡code¡¡you¡¡want¡£¡¡When¡¡you¡¡set¡¡Option¡¡Strict¡¡to¡¡On£»¡¡you¡¡are¡¡saying¡¡that¡¡you¡¡don¡¯t¡¡want¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡support¡¡weakly¡¡typed¡¡code¡£¡¡The¡¡flag¡¡has¡¡no¡¡effect¡¡on¡¡dynamic¡¡typing¡£¡¡The¡¡Option¡¡Explicit¡¡flag¡¡does¡¡not¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡affect¡¡weakly¡¡typed¡¡code£»¡¡but¡¡it¡¡partially¡¡affects¡¡dynamic¡¡typed¡¡code¡£¡¡Consider¡¡the¡¡following¡¡code¡¡that¡¡piles¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡when¡¡Option¡¡¡¡Explicit¡¡is¡¡set¡¡to¡¡Off¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡=¡¡10¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡is¡¡an¡¡assignment£»¡¡but¡¡you¡¡don¡¯t¡¡know¡¡if¡¡the¡¡variable¡¡is¡¡declared¡¡in¡¡the¡¡file£»¡¡in¡¡the¡¡class£»¡¡or¡¡local¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡method¡£¡¡The¡¡variable¡¡could¡¡be¡¡defined¡¡out¡¡of¡¡the¡¡blue¡¡and¡¡then¡¡used¡£¡¡Dynamic¡¡typing¡¡allows¡¡this£»¡¡but¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡again£»¡¡after¡¡the¡¡variable¡¡has¡¡been¡¡assigned£»¡¡it¡¡stays¡¡the¡¡same¡¡type¡£¡¡When¡¡you¡¡set¡¡Option¡¡¡¡Explicit¡¡to¡¡On£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡you¡¡are¡¡making¡¡an¡¡explicit¡¡declaration¡¡of¡¡the¡¡variable¡¡a¡¡requirement¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡With¡¡all¡¡of¡¡these¡¡options£»¡¡you¡¡are¡¡left¡¡wondering¡¡which¡¡bination¡¡of¡¡flags¡¡you¡¡want¡£¡¡The¡¡answer¡¡is¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡it¡¡depends¡¡on¡¡what¡¡style¡¡of¡¡programmer¡¡you¡¡are¡£¡¡If¡¡you¡¡want¡¡a¡¡traditional¡¡language¡¡£¨like¡¡C#£»¡¡Java£»¡¡C£«£«£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡so¡¡on£©£»¡¡then¡¡you¡¡should¡¡have¡¡both¡¡flags¡¡set¡¡to¡¡On¡£¡¡If¡¡you¡¡want¡¡a¡¡more¡¡dynamic¡¡programming¡¡language¡¡£¨like¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Python£»¡¡Ruby£»¡¡PHP£»¡¡and¡¡so¡¡on£©£»¡¡then¡¡you¡¡should¡¡have¡¡both¡¡flags¡¡set¡¡to¡¡Off¡£¡¡Unless¡¡you¡¡have¡¡experience¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dynamic¡¡programming¡¡environment¡¡and¡¡know¡¡what¡¡side¡¡effects¡¡may¡¡occur£»¡¡you¡¡should¡¡start¡¡off¡¡taking¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡traditional¡¡language¡¡approach¡£¡¡For¡¡that¡¡reason£»¡¡the¡¡code¡¡in¡¡this¡¡book¡¡is¡¡written¡¡with¡¡both¡¡flags¡¡set¡¡to¡¡On¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡can¡¡define¡¡the¡¡Option¡¡Strict¡¡and¡¡Option¡¡Explicit¡¡flags¡¡in¡¡the¡¡source¡¡code£»¡¡as¡¡shown¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡examples¡¡in¡¡the¡¡previous¡¡¡°Quoting¡¡Strings¡±¡¡section£»¡¡or¡¡you¡¡can¡¡set¡¡them¡¡in¡¡the¡¡pile¡¡settings¡¡of¡¡the¡¡individual¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡project¡¡settings¡¡or¡¡for¡¡the¡¡whole¡¡of¡¡Visual¡¡Basic¡¡Express¡£¡¡To¡¡set¡¡them¡¡for¡¡a¡¡project£»¡¡right¡­click¡¡the¡¡project¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡name¡¡and¡¡select¡¡Properties¡¡¡¡pile¡£¡¡The¡¡two¡¡settings¡¡are¡¡in¡¡the¡¡drop¡­down¡¡boxes¡¡at¡¡the¡¡top¡¡of¡¡the¡¡page¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡set¡¡the¡¡options¡¡for¡¡all¡¡projects£»¡¡select¡¡Tools¡¡¡¡Options£»¡¡and¡¡then¡¡select¡¡Projects¡¡and¡¡Solutions¡¡¡¡VB¡¡Defaults¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡89¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Character¡¡Mapping¡¡



A¡¡single¡¡character¡¡takes¡¡16¡¡bits¡¡of¡¡space£»¡¡and¡¡the¡¡space¡¡that¡¡a¡¡string¡¡consumes¡¡depends¡¡on¡¡the¡¡¡¡

number¡¡of¡¡characters¡¡in¡¡a¡¡buffer¡£¡¡If¡¡a¡¡buffer¡¡is¡¡10¡¡characters¡¡long£»¡¡then¡¡the¡¡entire¡¡buffer¡¡takes¡¡up¡¡¡¡

160¡¡bits¡¡of¡¡space¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡A¡¡single¡¡character¡¡is¡¡16¡¡bits¡¡long¡¡so¡¡that¡¡a¡¡buffer¡¡can¡¡store¡¡text¡¡in¡¡a¡¡multitude¡¡of¡¡different¡¡¡¡

formats¡£¡¡The¡¡standardized¡¡length¡¡is¡¡due¡¡to¡¡a¡¡standard¡¡called¡¡Unicode¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡the¡¡character¡¡a¡£¡¡Philosophically£»¡¡how¡¡do¡¡you¡¡know¡¡that¡¡an¡¡a¡¡is¡¡an¡¡a£¿¡¡For¡¡humans£»¡¡¡¡

that¡¯s¡¡easy¡¡because¡¡our¡¡brains¡¡are¡¡trained¡¡to¡¡recognize¡¡the¡¡curve¡¡and¡¡look¡¡of¡¡an¡¡a¡£¡¡Now¡¡look¡¡at¡¡¡¡

the¡¡Russian¡¡letter¡¡shown¡¡in¡¡Figure¡¡3¡­10¡£¡¡



Figure¡¡3¡­10¡£¡¡A¡¡Russian¡¡letter¡¡



¡¡¡¡¡¡¡¡¡¡¡¡What¡¡letter¡¡does¡¡Figure¡¡3¡­10¡¡show£¿¡¡It¡¡looks¡¡like¡¡an¡¡H£»¡¡right£¿¡¡But¡¡paring¡¡it¡¡to¡¡the¡¡English¡¡¡¡

language£»¡¡it¡¡is¡¡an¡¡N¡£¡¡The¡¡Russian¡¡language¡¡has¡¡its¡¡own¡¡set¡¡of¡¡letters£»¡¡and¡¡someone¡¡has¡¡deter

mined¡¡that¡¡a¡¡Russian¡¡H¡¡is¡¡an¡¡English¡¡N¡£¡¡Figure¡¡3¡­11¡¡is¡¡a¡¡mapping¡¡of¡¡the¡¡Russian¡¡letters¡¡to¡¡the¡¡¡¡

English¡¡letters¡£¡¡



Figure¡¡3¡­11¡£¡¡Mapping¡¡of¡¡Russian¡¡letters¡¡to¡¡English¡¡letters¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡90¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡I¡¡were¡¡learning¡¡Russian£»¡¡I¡¡would¡¡want¡¡the¡¡mapping¡¡provided¡¡in¡¡Figure¡¡3¡­11¡£¡¡The¡¡mapping¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡gives¡¡me¡¡an¡¡idea¡¡of¡¡what¡¡each¡¡letter¡¡in¡¡Russian¡¡represents¡£¡¡You¡¡could¡¡think¡¡of¡¡Figure¡¡3¡­11¡¡as¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lookup¡¡table¡£¡¡The¡¡puter¡¡has¡¡the¡¡same¡¡sort¡¡of¡¡need£»¡¡because¡¡a¡¡puter¡¡does¡¡not¡¡under

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡stand¡¡letters¡£¡¡A¡¡puter¡¡understands¡¡only¡¡numbers¡¡and¡¡thus¡¡uses¡¡lookup¡¡tables¡¡that¡¡map¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡set¡¡of¡¡letters¡¡to¡¡a¡¡set¡¡of¡¡numbers¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡There¡¡are¡¡many¡¡lookup¡¡tables£»¡¡such¡¡as¡¡American¡¡Standard¡¡Code¡¡for¡¡Information¡¡Inter

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡change¡¡£¨ASCII£©¡£¡¡For¡¡example£»¡¡using¡¡ASCII£»¡¡the¡¡letter¡¡a¡¡maps¡¡to¡¡the¡¡number¡¡97¡£¡¡The¡¡problem¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡ASCII¡¡is¡¡that¡¡it¡¡works¡¡well¡¡for¡¡English£»¡¡but¡¡works¡¡horribly¡¡for¡¡other¡¡languages¡£¡¡ASCII¡¡was¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡extended¡¡to¡¡deal¡¡with¡¡Western¡¡European¡¡languages£»¡¡but¡¡still¡¡fails¡¡for¡¡languages¡¡such¡¡as¡¡Chinese£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Russian£»¡¡and¡¡Arabic¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡solution¡¡chosen¡¡by¡¡¡¡is¡¡Unicode¡£¡¡Unicode¡¡is¡¡the¡¡definition¡¡of¡¡a¡¡set¡¡of¡¡lookup¡¡tables¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡map¡¡to¡¡letters¡¡for¡¡all¡¡of¡¡the¡¡languages¡¡of¡¡the¡¡world¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡most¡¡part£»¡¡you¡¡will¡¡not¡¡have¡¡to¡¡concern¡¡yourself¡¡with¡¡the¡¡Unicode£»¡¡because¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡manages¡¡everything¡¡transparently¡£¡¡This¡¡was¡¡not¡¡the¡¡case¡¡many¡¡years¡¡ago£»¡¡when¡¡programmers¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡had¡¡to¡¡manage¡¡the¡¡lookup¡¡tables¡¡themselves¡£¡¡So¡¡consider¡¡yourself¡¡lucky¡¡that¡¡you¡¡did¡¡not¡¡expe

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡rience¡¡this¡¡pain¡¡in¡¡developing¡¡multilingual¡¡applications¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dealing¡¡with¡¡Languages¡¡and¡¡Cultures¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Managing¡¡strings¡¡in¡¡¡¡does¡¡not¡¡stop¡¡with¡¡Unicode¡£¡¡¡¡is¡¡very¡¡innovative¡¡in¡¡that¡¡it¡¡under

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡stands¡¡concepts¡¡such¡¡as¡¡culture¡¡and¡¡language£»¡¡which¡¡are¡¡a¡¡reflection¡¡of¡¡how¡¡humans¡¡speak¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡live¡£¡¡The¡¡ideas¡¡of¡¡culture¡¡and¡¡language¡¡do¡¡not¡¡exist¡¡in¡¡other¡¡programming¡¡environments¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Consider¡¡Switzerland¡¡as¡¡an¡¡example¡£¡¡Throughout¡¡Switzerland£»¡¡there¡¡are¡¡mountains¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡happen¡¡to¡¡separate¡¡four¡¡individual¡¡languages£º¡¡German£»¡¡Italian£»¡¡Romansch£»¡¡and¡¡French¡£¡¡Even¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡the¡¡four¡¡languages£»¡¡the¡¡Swiss¡¡all¡¡trade¡¡the¡¡same¡¡currency¡¡and¡¡write¡¡numbers¡¡the¡¡same¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡way¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡previous¡¡programming¡¡environments£»¡¡the¡¡language¡¡would¡¡be¡¡tied¡¡to¡¡a¡¡particular¡¡country¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡This¡¡works¡¡fine¡¡for¡¡France£»¡¡Germany£»¡¡and¡¡the¡¡United¡¡States£»¡¡but¡¡fails¡¡miserably¡¡for¡¡Canada£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Switzerland£»¡¡Belgium£»¡¡and¡¡India¡£¡¡You¡¡need¡¡to¡¡separate¡¡language¡¡from¡¡culture£»¡¡because¡¡multiple¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡languages¡¡are¡¡used¡¡in¡¡different¡¡cultures¡£¡¡For¡¡example£»¡¡Italian¡¡is¡¡spoken¡¡in¡¡Switzerland¡¡and¡¡Italy¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡French¡¡is¡¡spoken¡¡in¡¡France£»¡¡Switzerland£»¡¡Luxembourg£»¡¡and¡¡Canada¡£¡¡German¡¡is¡¡spoken¡¡in¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Germany£»¡¡Switzerland£»¡¡and¡¡Austria¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Setting¡¡Culture¡¡and¡¡Language¡¡in¡¡Windows¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Windows¡¡operating¡¡system¡¡allows¡¡you¡¡to¡¡set¡¡the¡¡culture¡¡and¡¡language¡¡of¡¡your¡¡puter£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡regardless¡¡of¡¡the¡¡language¡¡in¡¡which¡¡Windows¡¡is¡¡operating¡£¡¡Figure¡¡3¡­12¡¡shows¡¡an¡¡example¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡example¡¡in¡¡Figure¡¡3¡­12¡¡is¡¡running¡¡a¡¡German¡¡version¡¡of¡¡Windows¡¡in¡¡Switzerland¡£¡¡The¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡language¡¡is¡¡English£»¡¡and¡¡the¡¡culture¡¡is¡¡Canada¡£¡¡It¡¡would¡¡seem¡¡that¡¡Windows¡¡would¡¡get¡¡confused£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡but¡¡in¡¡fact£»¡¡if¡¡you¡¡write¡¡your¡¡¡¡application¡¡properly£»¡¡multilanguage¡¡support¡¡is¡¡simple¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡91¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



Figure¡¡3¡­12¡£¡¡Setting¡¡the¡¡culture¡¡and¡¡language¡¡in¡¡Windows¡¡



Parsing¡¡and¡¡Processing¡¡Numbers¡¡



The¡¡culture¡¡and¡¡country¡¡bee¡¡important¡¡when¡¡interacting¡¡with¡¡numbers¡¡and¡¡dates¡¡that¡¡¡¡

are¡¡stored¡¡as¡¡strings¡£¡¡Imagine¡¡retrieving¡¡a¡¡string¡¡buffer¡¡with¡¡an¡¡embedded¡¡number¡¡and¡¡then¡¡¡¡

attempting¡¡to¡¡perform¡¡an¡¡addition£»¡¡as¡¡illustrated¡¡by¡¡Figure¡¡3¡­13¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Variables¡¡a¡¡and¡¡b¡¡are¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡assigned¡¡buffers¡¡that¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡represent¡¡numbers¡¡



¡¡Dim¡¡a¡¡As¡¡String¡¡=¡¡¡¨1¡¨¡¡

Dim¡¡b¡¡As¡¡String¡¡=¡¡¡¨2¡¨¡¡

Dim¡¡c¡¡As¡¡String¡¡=¡¡a¡¡£«¡¡b¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Adding¡¡two¡¡buffers¡¡is¡¡a¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡concatenation¡¡operation¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Variable¡¡c¡¡contains¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡value¡¡12¡¡



Figure¡¡3¡­13¡£¡¡Performing¡¡arithmetic¡¡on¡¡numbers¡¡represented¡¡as¡¡strings¡¡can¡¡lead¡¡to¡¡unexpected¡¡results¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡92¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Adding¡¡numbers¡¡is¡¡performing¡¡a¡¡mathematical¡¡operation¡£¡¡When¡¡the¡¡add¡¡operation¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡performed¡¡on¡¡strings£»¡¡it¡¡always¡¡results¡¡in¡¡a¡¡buffer¡¡concatenation¡£¡¡The¡¡add¡¡operation¡¡is¡¡a¡¡very¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡simple¡¡way¡¡to¡¡concatenate¡¡string¡¡buffers¡¡together¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡However£»¡¡concatenation¡¡is¡¡not¡¡the¡¡aim¡¡of¡¡the¡¡example¡£¡¡The¡¡aim¡¡is¡¡to¡¡treat¡¡the¡¡strings¡¡as¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡numbers¡¡and¡¡then¡¡add¡¡the¡¡numbers¡¡so¡¡that¡¡c¡¡contains¡¡the¡¡value¡¡¡¡3¡¡£¨1¡¡£«¡¡2¡¡=¡¡3£©¡£¡¡The¡¡rewritten¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡version¡¡of¡¡the¡¡example¡¡is¡¡shown¡¡in¡¡Figure¡¡3¡­14¡£¡¡This¡¡code¡¡parses¡¡a¡¡string¡¡into¡¡an¡¡integer¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Integer¡¡is¡¡a¡¡value¡¡type£»¡¡but¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡recognizes¡¡the¡¡methods¡¡associated¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡with¡¡the¡¡value¡¡types¡¡that¡¡can¡¡be¡¡used¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡parse¡¡string¡¡buffers¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡a¡¡As¡¡Integer¡¡=¡¡Integer¡£Parse£¨¡¨1¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡b¡¡As¡¡Integer¡¡=¡¡Integer¡£Parse£¨¡¨2¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡c¡¡As¡¡Integer¡¡=¡¡a¡¡£«¡¡b¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Variable¡¡c¡¡contains¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Variables¡¡a¡¡and¡¡b¡¡are¡¡assigned¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡value¡¡3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡values¡¡that¡¡represent¡¡the¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡parsed¡¡string¡¡buffers¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­14¡£¡¡Parsing¡¡strings¡¡into¡¡integers¡¡before¡¡doing¡¡the¡¡arithmetic¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡type¡¡Integer¡¡has¡¡a¡¡¡¡Parse£¨£©¡¡method¡¡that¡¡can¡¡be¡¡used¡¡to¡¡turn¡¡a¡¡string¡¡into¡¡an¡¡integer¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡parsing¡¡works¡¡only¡¡if¡¡the¡¡buffer¡¡is¡¡a¡¡valid¡¡number¡£¡¡If¡¡the¡¡buffer¡¡contains¡¡letters¡¡or¡¡an¡¡invalid¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡number£»¡¡an¡¡error¡¡will¡¡be¡¡generated¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡the¡¡code¡¡can¡¡cope¡¡with¡¡a¡¡failed¡¡string¡¡conversion£»¡¡the¡¡solution¡¡used¡¡by¡¡the¡¡parsing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡routines¡¡is¡¡to¡¡generate¡¡an¡¡exception¡¡that¡¡a¡¡program¡¡could¡¡process¡£¡¡Alternatively£»¡¡a¡¡fail¡­safe¡¡way¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡parse¡¡a¡¡number¡¡is¡¡to¡¡use¡¡TryParse£¨£©£»¡¡as¡¡in¡¡the¡¡following¡¡example¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡value¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡Integer¡£TryParse£¨¡¨1¡¨£»¡¡value£©¡¡Then¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡TryParse£¨£©¡¡method¡¡does¡¡not¡¡return¡¡an¡¡integer¡¡value£»¡¡but¡¡instead¡¡returns¡¡a¡¡¡¡Boolean¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡flag£»¡¡indicating¡¡whether¡¡the¡¡buffer¡¡could¡¡be¡¡parsed¡£¡¡If¡¡the¡¡return¡¡value¡¡is¡¡True£»¡¡then¡¡the¡¡buffer¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡could¡¡be¡¡parsed£»¡¡and¡¡the¡¡result¡¡is¡¡stored¡¡in¡¡the¡¡parameter¡¡value¡£¡¡You¡¡can¡¡parse¡¡other¡¡number¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types¡¡using¡¡the¡¡same¡¡techniques¡¡£¨for¡¡example£»¡¡Single¡£TryParse£¨£©£©¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡There¡¡are¡¡more¡¡variations¡¡in¡¡how¡¡a¡¡number¡¡can¡¡be¡¡parsed¡£¡¡For¡¡example£»¡¡how¡¡would¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡number¡¡100¡¡be¡¡parsed£»¡¡if¡¡the¡¡number¡¡100¡¡is¡¡hexadecimal£¿¡¡£¨puters¡¡use¡¡hexadecimal¡¡numbers¡££©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Here¡¡is¡¡an¡¡example¡¡of¡¡hexadecimal¡¡conversion£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡System¡£Globalization¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¡¡¡£¡¡¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡ParseHexadecimal£¨£©¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡value¡¡As¡¡Integer=¡¡Integer¡£Parse£¨¡¨100¡¨£»¡¡NumberStyles¡£HexNumber£©¡¡

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


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡93¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

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



¡¡¡¡¡¡¡¡¡¡This¡¡example¡¡uses¡¡a¡¡variant¡¡of¡¡¡¡Parse£¨£©£»¡¡which¡¡has¡¡an¡¡additional¡¡second¡¡parameter¡¡that¡¡¡¡

represents¡¡the¡¡format¡¡of¡¡the¡¡number¡£¡¡In¡¡this¡¡case£»¡¡the¡¡second¡¡parameter¡¡indicates¡¡that¡¡the¡¡¡¡

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