³õʶVBA£ºµÚËÄ¿Î ¼ÆËãÆ÷´úÂëµÄ±àд
ÉϽڿÎÎÒÃÇÒѾ¶Ô³ÌÐò´ó¸Å¿ò¼Ü×öÁË·ÖÎö£¬Õâ½Ú¿ÎÎÒÃǾÍÀ´¿ªÊ¼±àд³ÌÐò´úÂë¡£ÓÉÓÚ¼ÆËãÆ÷Ö÷ÒªÊǶԸ÷λ°´Å¥×ö³ö·´Ó¦£¬ËùÒÔÎÒÃǵĴúÂëÒ²´ó¶à¶¼ÊÇÔÚ°´Å¥µÄµ¥»÷ʼþÖз¢Éú£¬ÉϽڿÎÎÒÃÇ°Ñ°´Å¥×öÁËÒ»¸ö·ÖÀ࣬¹²Îª5ÀࣺÇåÁã°´Å¥¡¢µÈºÅ°´Å¥¡¢Êý×Ö°´Å¥¡¢¼ÆËã·ûºÅ°´Å¥¡¢Ð¡Êýµã°´Å¥¡£Ð¡Êýµã°´Å¥¼°µÈºÅ°´Å¥Ïà¶Ô±È½Ï¸´ÔÓÒ»µã£¬ÎÒÃÇ´ÓÒ×µ½ÄÑ£¬ÏÈ×ö¼òµ¥µÄ£¬ÔÙ×ö¸´Ôӵġ£Ê×ÏÈÉùÃ÷¼¸¸ö±äÁ¿£º Option Compare Database ¡®Õâ¾äÊdzÌÐòÔ±¾¾ÍÓеģ¬ÔÚÕâ¾äÏÂÃæÊäÈëÏÂÃæÁ½¾ä Dim dblNum1 As Double ¡®¶¨Òå±äÁ¿À´±£´æµÚÒ»¸ö²Î¼ÓÔËËãµÄÊýÖµ Dim strOperator As String ¡®¶¨Òå±äÁ¿À´±£´æÔËËã·ûºÅ 1¡¢ÇåÁã°´Å¥ Ö»ÓÐÒ»¾ä³ÌÐò£¬×÷ÓÃÊÇ°Ñ´°ÌåÉϵÄÎı¾¿òÇåÁã¡£ Private Sub cmdClear_Click() txtResult = 0 End Sub °´ÏÂÕâ¸ö°´Å¥Ö®ºó£¬Îı¾¿òÀïµÄֵΪ0¡£ 2¡¢Êý×Ö°´Å¥ ÕâÒ»ÀàµÄ°´Å¥¹²ÓÐ10¸ö£¬µ±°´ÏÂÕâÀà°´Å¥¾Í°Ñ´ú±íÕâ¸ö°´Å¥µÄÊý×Ö¼ÓÔÚÎı¾¿òÏÖÓÐÊý×ֵĺóÃæ¡£ Private Sub cmd0_Click() txtResult = txtResult & 0 End Sub ÕâÊÇcmd0°´Å¥µÄʼþ£¬ÆäËüÊý×Ö°´Å¥µÄʼþÒ²ÀàËÆ£¬Ö»Ðè°Ñ×îºóÃæµÄ0¸ÄΪÏàÓ¦Êý×Ö¾ÍÐÐÁË¡£ 3¡¢ÔËËã·ûºÅ°´Å¥ µ±°´ÏÂÔËËã·ûºÅ°´Å¥Ê±£¬×öÈý¼þÊ£º a)°ÑÎı¾¿òÀïµÄÊýÖµ±£´æµ½±äÁ¿dblNum1ÖÐ dblNum1 = Val(txtResult) b)°Ñ´ú±í¸Ã°´Å¥µÄÔËËã·ûºÅ±£´æµ½±äÁ¿strOperatorÖÐ strOperator = "+" ¡®ÕâÊÇ°´Ï¡±+¡±ºÅ°´Å¥µÄÓï¾ä£¬ÆäËüÔËËã°´Å¥Òª»»³É¶ÔÓ¦µÄ·ûºÅ c)°ÑÎı¾¿òÇåÁ㣬Ï൱ÓÚ°´ÏÂÇåÁã°´Å¥ txtResult = 0 4¡¢µÈºÅ°´Å¥ µ±°´ÏµȺŰ´Å¥Ê±£¬³ÌÐò±ØÐëÅжÏÄãÏëÔËÐÐʲôÔËË㣬Åжϵĸù¾Ý¾ÍÊDZ£´æÔÚ±äÁ¿strOperatorÖеÄÔËËã·û£¬ÔËË㻹ҪÓÐÔËËã¶ÔÏ󣬶ÔÏóµÄÀ´Ô´Ò»ÊDZ£´æÔÚ±äÁ¿dblnum1ÖеÄÊýÖµ£¬Ò»ÊÇÎı¾¿òÖеÄÊýÖµ¡£ÅжÏÓï¾äÓÐÐí¶àÖÖ£¬±ÈÈçifÓï¾äÒÔ¼° select caseÓï¾ä£¬ÎÒÃÇÔÚÕâÀï²ÉÓõÄÊÇselect caseÓï¾ä£¬ifÓï¾äÔÚСÊýµã°´Å¥Àï»áÓõ½¡£ Select Óï¾äµÄÓï·¨£º Select Case testexpression [Case expressionlist-n [statements-n]] ... [Case Else [elsestatements]] End Select Ó﷨˵Ã÷£º testexpression ±ØÒª²ÎÊý¡£ÈκÎÊýÖµ±í´ïʽ»ò×Ö·û´®±í´ïʽ¡£ expressionlist-n Èç¹ûÓÐ Case ³öÏÖ£¬ÔòΪ±ØÒª²ÎÊý¡£ÆäÐÎʽΪ expression£¬expression To expression£¬Is comparisonoperator expressionµÄÒ»¸ö»ò¶à¸ö×é³ÉµÄ·Ö½çÁÐ±í¡£To ¹Ø¼ü×Ö¿ÉÓÃÀ´Ö¸¶¨Ò»¸öÊýÖµ·¶Î§¡£Èç¹ûʹÓà To ¹Ø¼ü×Ö£¬Ôò½ÏСµÄÊýÖµÒª³öÏÖÔÚ To ֮ǰ¡£Ê¹Óà Is ¹Ø¼ü×Öʱ£¬Ôò¿ÉÒÔÅäºÏ±È½ÏÔËËã·û£¨³ý Is ºÍ Like Ö®Í⣩À´Ö¸¶¨Ò»¸öÊýÖµ·¶Î§¡£Èç¹ûûÓÐÌṩ£¬Ôò Is ¹Ø¼ü×ֻᱻ×Ô¶¯²åÈë¡£ statements-n ¿ÉÑ¡²ÎÊý¡£Ò»Ìõ»ò¶àÌõÓï¾ä£¬µ± testexpression Æ¥Åäexpressionlist-nÖеÄÈκβ¿·ÖʱִÐС£ elsestatements ¿ÉÑ¡²ÎÊý¡£Ò»Ìõ»ò¶àÌõÓï¾ä£¬µ± testexpression ²»Æ¥Åä Case ×Ó¾äµÄÈκβ¿·ÖʱִÐС£ ¡ù¸üÏêϸµÄ˵Ã÷Çë²éÔÄAccess°ïÖú Óï·¨ÒѾ֪µÀÁË£¬ÄÇÏÂÃæ¾ÍÀ´¿ªÊ¼ÓÃselect caseÀ´±àдµÈºÅ°´Å¥Ê¼þÖеijÌÐò£º Private Sub cmdEqual_Click() ¡®ÓÃstrOperatorÀ´×öΪѡÔñÌõ¼þ Select Case strOperator ¡®µ±strOperator=¡±+¡± Case "+" ¡®Îı¾¿òµÄÖµµÈÓÚ±äÁ¿dblnum1µÄÖµ¼ÓÎı¾¿òµÄÖµ¡£ÕâÀïÎÒÃÇʹÓÃÁËVALº¯Êý£¬ÒòΪÎı¾¿òÖеÄÖµÊÇÒ»¸ö×Ö·û´®£¬¶ø±äÁ¿ÖеÄÖµÊÇË«¾«¶ÈÊýÖµÐÍ£¬ËùÒÔÏÈÒªÓÃvalº¯Êý°ÑÎı¾¿òÖеÄֵת»»ÎªÊýÖµÐÍ¡£ txtResult = dblNum1 + Val(txtResult) ¡®ÏÂÃæµÄ²»×ö½âÊÍÁË£¬ÒòΪ¶¼ÊÇÒ»ÑùµÄÓï¾ä Case "-" txtResult = dblNum1 - Val(txtResult) Case "*" txtResult = dblNum1 * Val(txtResult) Case "/" txtResult = dblNum1 / Val(txtResult) End Select End Sub »¹ÓÐÒ»¸öСÊýµã°´Å¥µÄ³ÌÐòû×ö£¬ÓÉÓÚʱ¼ä¹Øϵ£¬Ï½ڿÎÔÙ˵£¬½ñÌìÒÑ»¨ÁËÌ«¶àʱ¼äÔÚÕâÁË£¬ÔÙ²»È¥¹¤×÷ÀÏ°åÒª³´ÎÒöÏÓãÁË£º£©
--------------------------------------------------------------------------------
Ïà¹ØÎÄÕÂ
ûÓÐÏà¹ØÎÄÕÂ
|