Option Explicit
Dim Op1, Op2 ' é¢å
è¾å
¥æä½æ°ã
Dim DecimalFlag As Integer ' å°æ°ç¹åå¨åï¼
Dim NumOps As Integer ' æä½æ°ä¸ªæ°ã
Dim LastInput ' æ示ä¸ä¸æ¬¡æé®äºä»¶çç±»åã
Dim OpFlag ' æ示æªå®æçæä½ã
Dim TempReadout
' C (åæ¶) æé®ç Click äºä»¶è¿ç¨
' éæ°è®¾ç½®æ¾ç¤ºå¹¶åå§ååéã
Private Sub Cancel_Click()
Readout = Format(0, "0.")
Op1 = 0
Op2 = 0
Form_Load
End Sub
' CE (åæ¶è¾å
¥) æé®ç Click äºä»¶è¿ç¨ã
Private Sub CancelEntry_Click()
Readout = Format(0, "0.")
DecimalFlag = False
LastInput = "CE"
End Sub
' å°æ°ç¹ (.) æé®ç Click äºä»¶è¿ç¨
' å¦æä¸ä¸æ¬¡æé®ä¸ºè¿ç®ç¬¦ï¼åå§å readout 为 "0."ï¼
' å¦åæ¾ç¤ºæ¶è¿½å ä¸ä¸ªå°æ°ç¹ã
Private Sub Decimal_Click()
If LastInput <> "NUMS" Then
Readout = Format(0, "0.")
End If
DecimalFlag = True
LastInput = "NUMS"
End Sub
' çªä½çåå§åè¿ç¨
' 设置ææåé为å
¶åå§å¼ã
Private Sub Form_Load()
DecimalFlag = False
NumOps = 0
LastInput = "NONE"
OpFlag = ""
Readout = Format(0, "0.")
End Sub
'æ¹åæ°åçæ£è´å·
Private Sub negcmd_Click()
If LastInput <> "OPS" Or OpFlag = "=" Then
If Left(Readout, 1) <> "-" Then
Readout = "-" & Readout
Else
Readout = Right(Readout, Len(Readout) - 1)
End If
End If
End Sub ' æ°åé® (0-9) ç Click äºä»¶è¿ç¨
' åæ¾ç¤ºä¸çæ°è¿½å æ°æ°ã
Private Sub Number_Click(Index As Integer)
If LastInput <> "NUMS" Then
Readout = Format(0, ".")
DecimalFlag = False
End If
If DecimalFlag Then
Readout = Readout + Number(Index).Caption
Else
Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
End If
LastInput = "NUMS"
End Sub
' è¿ç®ç¬¦ (+, -, x, /, =) ç Click äºä»¶è¿ç¨
' å¦ææ¥ä¸æ¥çæé®æ¯æ°åé®ï¼å¢å NumOpsã
' å¦ææä¸ä¸ªæä½æ°ï¼å设置 Op1ã
' å¦ææ两个æä½æ°ï¼åå° Op1 设置为 Op1 ä¸
' å½åè¾å
¥å符串çè¿ç®ç»æï¼å¹¶æ¾ç¤ºç»æã
Private Sub Operator_Click(Index As Integer)
TempReadout = Readout
If LastInput <> "OPS" Then
NumOps = NumOps + 1
End If
Select Case NumOps
Case 0
'ä»ä¹ä¹ä¸å
Case 1
Op1 = Readout
Case 2
Op2 = TempReadout
Select Case OpFlag
Case "+"
Op1 = CDbl(Op1) + CDbl(Op2)
Case "-"
Op1 = CDbl(Op1) - CDbl(Op2)
Case "X"
Op1 = CDbl(Op1) * CDbl(Op2)
Case "/"
If Op2 = 0 Then
MsgBox "é¤æ°ä¸è½ä¸ºé¶", 48, "计ç®å¨"
Else
Op1 = CDbl(Op1) / CDbl(Op2)
End If
Case "="
Op1 = CDbl(Op2)
Case "%"
Op1 = CDbl(Op1) * CDbl(Op2)
End Select
Readout = Op1
NumOps = 1
End Select
LastInput = "OPS"
OpFlag = Operator(Index).Caption
End Sub
' ç¾åæ¯é® (%) ç Click äºä»¶è¿ç¨
Private Sub Percent_Click()
If LastInput <> "OPS" Or OpFlag = "=" Then
Readout = Readout / 100
LastInput = "PER"
DecimalFlag = True
End If
End Sub
温馨提示:答案为网友推荐,仅供参考