1、计算器的设计
Option Explicit
Dim str1 As String
Dim str2 As String
Dim strtemp As String
Dim blnStatus As Boolean
Dim intOperate As Integer
Dim strtemp1 As String
Private Sub cmdBack_Click()
If Not blnStatus Then strtemp = str1 Else strtemp = str2
If Len(strtemp) > 0 Then strtemp = Lef
2、t(strtemp, Len(strtemp) - 1)
txtDisplay = strtemp
If Not blnStatus Then str1 = strtemp Else str2 = strtemp
End Sub
Private Sub cmdmc_Click()
cmdmstore.Caption = ""
txtDisplay.Text = strtemp1
str1 = ""
blnStatus = False
End Sub
Private Sub cmdmr_Click()
txtDisplay.Text = strtemp1
st
3、r1 = ""
blnStatus = False
End Sub
Private Sub cmdms_Click()
cmdmstore.Caption = "m"
strtemp1 = str1
str1 = ""
blnStatus = False
End Sub
Private Sub cmdCalc_Click(Index As Integer)
str2 = ""
txtDisplay.Text = ""
blnStatus = True
intOperate = Index
End Sub
Private Sub cmdEqual_C
4、lick(Index As Integer)
If Len(Trim(str1)) = 0 Or Len(Trim(str1)) = 0 Then
blnStatus = False
Exit Sub
End If
Dim dbl1 As Double
Dim dbl2 As Double
dbl1 = Val(str1)
dbl2 = Val(str2)
Select Case intOperate
Case 0
txtDisplay.Text = dbl1 + dbl2
Case 1
txtDisplay.Text = dbl1 - dbl2
Case 2
t
5、xtDisplay.Text = dbl1 * dbl2
Case 3
If dbl2 = 0 Then
MsgBox "除数不能为零!", 16, "计算器"
Exit Sub
End If
txtDisplay.Text = dbl1 / dbl2
End Select
blnStatus = False
str1 = ""
str2 = ""
End Sub
Private Sub cmdM_Click(Index As Integer)
If Len(Trim(str1)) = 0 Or Len(Trim(strtemp1)) = 0 Then
blnS
6、tatus = False
Exit Sub
End If
Dim dbl1 As Double
Dim dbl2 As Double
dbl1 = Val(str1)
dbl2 = Val(strtemp1)
strtemp1 = dbl1 + dbl2
If Len(strtemp1) > 0 And Left(strtemp1, 1) = "" Then
strtemp = "0" & strtemp
End If
blnStatus = True
str1 = strtemp1
str2 = ""
End Sub
Private Sub cmdNu
7、mber_Click(Index As Integer)
If Not blnStatus Then strtemp = str1 Else strtemp = str2
If Index < 10 Then
strtemp = strtemp + CStr(Index)
Else
If InStr(strtemp, ".") = 0 Then strtemp = strtemp + "."
End If
If Len(strtemp) > 1 And Left(strtemp, 1) = "0" And Mid(strtemp, 2, 1) <> "." Then
strte
8、mp = Right(strtemp, Len(strtemp) - 1)
End If
txtDisplay.Text = strtemp
If Not blnStatus Then str1 = strtemp Else str2 = strtemp
End Sub
Private Sub cmdPN_Click()
If Not blnStatus Then strtemp = str1 Else strtemp = str2
If Len(strtemp) > 0 And Left(strtemp, 1) = "-" Then
strtemp = Right(strtemp, Len(strtemp) - 1)
Else
strtemp = "-" & strtemp
End If
txtDisplay = strtemp
If Not blnStatus Then str1 = strtemp Else str2 = strtemp
End Sub