vb简易计算器
<div id="cnblogs_post_body">本人一觉醒来闲得无聊,正在学习VB,便用VB写个简易的计算器吧!巩固基础。。。代码如下:
<div class="cnblogs_code">1 /**2 *Author:乌鸟heart 3 *Version:1.04 */5 Dim IntX As Double '全局变量,用于存储计算的数值6 Dim IntOperationAs 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 Sub101 102 Private Sub CommandMinus_Click() '减法运算103 104 If IntOperation <> 0 Then '有运算标记的情况105 Call SavaToIntX106 IntOperation = 2107 Call Clear108 109 Else110 IntOperation = 2111 Call SavaToIntX112 Call Clear113 114 End If115 End Sub116 117 Private Sub CommandMultiple_Click() '乘法运算118 If IntOperation <> 0 Then '有运算标记的情况119 Call SavaToIntX120 IntOperation = 3121 Call Clear122 123 Else124 IntOperation = 3125 Call SavaToIntX126 Call Clear127 128 End If129 130 End Sub131 132 Private Sub CommandPlus_Click() '加法运算133 134 If IntOperation <> 0 Then '有运算标记的情况135 Call SavaToIntX136 IntOperation = 1137 Call Clear138 139 Else140 IntOperation = 1141 Call SavaToIntX142 Call Clear143 144 End If145 146 End Sub147 148 Private Sub CommandSlash_Click() '除法运算149 150 If IntOperation <> 0 Then '有运算标记的情况151 Call SavaToIntX152 IntOperation = 4153 Call Clear154 155 Else156 IntOperation = 4157 Call SavaToIntX158 Call Clear159 160 End If161 End Sub
页:
[1]