Private Sub Form_Load()
Dim sum1 As Double
Dim sum2 As Double
Dim operator As Integer
Dim pointflag As Boolean
Dim operatorNT As Boolean
pointflag = True ‘小数点判断变量并赋值
operatorNT = True ‘运算符次数判断并赋值
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 ‘ 数字键0
If Val(Text1.Text) = 0 Then
Exit Sub
Else
Text1.Text = Val(Text1.Text + Str(Index))
End If
Case 1 To 9 ‘数字键1到9
Text1.Text = Val(Text1.Text + Str(Index))
Text1.Text = Val(Text1.Text)
Case 10 ‘小数点
If ponitflag Then
Text1.Text = Text1.Text + "."
pointflag = False ‘小数点出现一次
End If
Case 11 ‘ = 号
sum2 = Text1.Text
Select Case operator
Case 1
Text1.Text = sum1 + sum2
Case 2
Text1.Text = sum1 - sum2
Case 3
Text1.Text = sum1 * sum2
Case 4
Text1.Text = sum1 / sum2
End Select
pointflag = True ‘使变量恢复初始
sum1 = Text1.Text
Case 12 To 15 ‘算术运算符
sum1 = Text1.Text
Text1.Text = "0"
operator = Index - 11
pointflag = True ‘使变量恢复初始
operatorNT = False
If Not operatorNT Then
sum2 = Text1.Text
End If
Case 16 ‘未使用的控件
Case 17 ‘清除键
Text1.Text = "0"
operatorNT = True ‘初始化变量
End Select
End Sub
Dim sum1 As Double
Dim sum2 As Double
Dim operator As Integer
Dim pointflag As Boolean
Dim operatorNT As Boolean
pointflag = True ‘小数点判断变量并赋值
operatorNT = True ‘运算符次数判断并赋值
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 ‘ 数字键0
If Val(Text1.Text) = 0 Then
Exit Sub
Else
Text1.Text = Val(Text1.Text + Str(Index))
End If
Case 1 To 9 ‘数字键1到9
Text1.Text = Val(Text1.Text + Str(Index))
Text1.Text = Val(Text1.Text)
Case 10 ‘小数点
If ponitflag Then
Text1.Text = Text1.Text + "."
pointflag = False ‘小数点出现一次
End If
Case 11 ‘ = 号
sum2 = Text1.Text
Select Case operator
Case 1
Text1.Text = sum1 + sum2
Case 2
Text1.Text = sum1 - sum2
Case 3
Text1.Text = sum1 * sum2
Case 4
Text1.Text = sum1 / sum2
End Select
pointflag = True ‘使变量恢复初始
sum1 = Text1.Text
Case 12 To 15 ‘算术运算符
sum1 = Text1.Text
Text1.Text = "0"
operator = Index - 11
pointflag = True ‘使变量恢复初始
operatorNT = False
If Not operatorNT Then
sum2 = Text1.Text
End If
Case 16 ‘未使用的控件
Case 17 ‘清除键
Text1.Text = "0"
operatorNT = True ‘初始化变量
End Select
End Sub
Dim sum2 As Double
以上的变量应是窗体级的。
字符会出现字节大小的问题吧