VB easy Calculator

Source: Internet
Author: User

As soon as I woke up, I was bored. I was learning VB, so I could use VB to write a simple calculator! Consolidate the foundation...
CodeAs follows:

 1 /** 2 * Author: wuniao heart  3 * Version: 1.0  4 */ 5   Dim Intx As   Double   '  Global variable used to store calculated values  6  Dim Operation peration As   Double       '  Mark Operation Type  7   Dim Isbegin As   Boolean   '  Indicates whether intx has been assigned a value  8   Public   Sub Clear () '  Clear command functions 9   10 Screen. Caption = ""  11   End sub  12   Public   Sub  Savatointx ()  13   14   Select   Case  Operation peration  15   16   Case  1   '  Addition  17   If Isbegin = False   Then  18 Intx = Val  (Screen. Caption)  19 Isbegin = True  20   Else  21 Intx = intx + Val (Screen. Caption)  22   End   If  23   24   Case   2   '  Subtraction  25   If Isbegin = False   Then  26 Intx = Val  (Screen. Caption) 27 Isbegin = True  28   Else  29 Intx = intx- Val  (Screen. Caption)  30   End   If  31   32   Case   3   '  Multiplication  33  If Isbegin = False   Then  34 Intx = Val  (Screen. Caption)  35 Isbegin = True  36   Else  37 Intx = intx * Val  (Screen. Caption)  38   ' Screen. Caption = intx  39   End   If  40   41   Case   4   '  Division  42   If Isbegin = False   Then  43 Intx = Val  (Screen. Caption) 44 Isbegin = True  45   Else  46 Intx = intx/ Val  (Screen. Caption)  47   End   If  48   49   End   Select  50   51   End sub 52   53   Private   Sub  Command0_click ()  54 Screen. Caption = screen. Caption & 0  55   End sub  56   Private   Sub  Commandmediaclick ()  57 Screen. Caption = screen. Caption & 1 58   End sub  59   Private   Sub  Command2_click ()  60 Screen. Caption = screen. Caption & 2  61   End sub  62   Private   Sub  Command3_click ()  63 Screen. Caption = screen. Caption &3  64   End sub  65   Private   Sub  Command4_click ()  66 Screen. Caption = screen. Caption & 4  67   End sub  68   Private   Sub  Command5_click ()  69 Screen. Caption = screen. Caption & 5  70   End sub  71   Private   Sub  Command6_click ()  72 Screen. Caption = screen. Caption & 6  73   End sub  74   Private   Sub  Command7_click () 75 Screen. Caption = screen. Caption & 7  76   End sub  77   Private   Sub  Command8_click ()  78 Screen. Caption = screen. Caption & 8  79   End sub  80   Private   Sub Command9_click ()  81 Screen. Caption = screen. Caption & 9  82   End sub  83   84   Private   Sub Commandclear_click () '  Clear command  85 Isbegin = False  86 Operation peration = 0 87 Intx = 0  88 Screen. Caption = ""  89   End sub  90   91   Private   Sub Commandequal_click () '  Equal sign operation  92   93   If Operation peration <> 0  Then   '  Computation mark  94   Call  Savatointx  95 Operation peration = 0  96 Isbegin = False  97 Screen. Caption = Intx  98   End   If  99  100   End sub  101   102   Private   Sub Commandminus_click () '  Subtraction  103   104   If Operation peration <> 0   Then   '  Computation mark  105  Call  Savatointx  106 Operation peration = 2  107   Call  Clear  108   109   Else  110 Operation peration = 2  111   Call  Savatointx  112  Call  Clear  113   114   End   If  115   End sub  116   117   Private   Sub Commandmultiple_click () '  Multiplication  118   If Operation peration <>0   Then   '  Computation mark  119   Call  Savatointx  120 Operation peration = 3  121   Call  Clear  122   123   Else  124 Operation peration = 3 125   Call  Savatointx  126   Call  Clear  127   128   End   If  129   130   End sub  131   132   Private   Sub Commandplus_click ()'  Addition operation  133   134   If Operation peration <> 0   Then   '  Computation mark  135   Call  Savatointx  136 Operation peration = 1  137   Call  Clear 138   139   Else  140 Operation peration = 1  141   Call  Savatointx  142   Call  Clear  143   144   End   If  145   146  End sub  147   148   Private   Sub Commandslash_click () '  Division  149   150   If Operation peration <> 0   Then   '  Computation mark  151   Call Savatointx  152 Operation peration = 4  153   Call  Clear  154   155   Else  156 Operation peration = 4  157   Call  Savatointx  158   Call Clear  159   160   End   If  161   End sub 

OK, done!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.