vb简易计算器

本人一觉醒来闲得无聊,正在学习VB,便用VB写个简易的计算器吧!巩固基础。。。 
代码如下:

  1 /**
  2 *Author:乌鸟heart    
  3 *Version:1.0
  4 */
  5 Dim IntX As Double '全局变量,用于存储计算的数值
  6 Dim IntOperation  As Double     '标记运算类型
  7 Dim isBegin As Boolean '标记是否已经给IntX赋值
  8 Public Sub Clear()     '清空命令函数
  9 
 10 screen.Caption = ""
 11 End Sub
 12 Public Sub SavaToIntX()
 13 
 14 Select Case IntOperation
 15 
 16 Case 1 '加法
 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 '减法
 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 '乘法
 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 '除法
 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 Command1_Click()
 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() '清空命令
 85 isBegin = False
 86 IntOperation = 0
 87 IntX = 0
 88 screen.Caption = ""
 89 End Sub
 90 
 91 Private Sub CommandEqual_Click() '等号运算
 92 
 93 If IntOperation <> 0 Then '有运算标记的情况
 94 Call SavaToIntX
 95 IntOperation = 0
 96 isBegin = False
 97 screen.Caption = IntX
 98 End If
 99 
100 End Sub
101 
102 Private Sub CommandMinus_Click() '减法运算
103 
104 If IntOperation <> 0 Then '有运算标记的情况
105 Call SavaToIntX
106 IntOperation = 2
107 Call Clear
108 
109 Else
110 IntOperation = 2
111 Call SavaToIntX
112 Call Clear
113 
114 End If
115 End Sub
116 
117 Private Sub CommandMultiple_Click() '乘法运算
118 If IntOperation <> 0 Then '有运算标记的情况
119 Call SavaToIntX
120 IntOperation = 3
121 Call Clear
122 
123 Else
124 IntOperation = 3
125 Call SavaToIntX
126 Call Clear
127 
128 End If
129 
130 End Sub
131 
132 Private Sub CommandPlus_Click() '加法运算
133 
134 If IntOperation <> 0 Then '有运算标记的情况
135 Call SavaToIntX
136 IntOperation = 1
137 Call Clear
138 
139 Else
140 IntOperation = 1
141 Call SavaToIntX
142 Call Clear
143 
144 End If
145 
146 End Sub
147 
148 Private Sub CommandSlash_Click() '除法运算
149 
150 If IntOperation <> 0 Then '有运算标记的情况
151 Call SavaToIntX
152 IntOperation = 4
153 Call Clear
154 
155 Else
156 IntOperation = 4
157 Call SavaToIntX
158 Call Clear
159 
160 End If
161 End Sub

OK,DONE!

 

原文地址:https://www.cnblogs.com/wuniaoheart/p/2675691.html