VB记事本中添加简单的计算器功能

来源:百度知道 编辑:UC知道 时间:2024/09/22 17:19:50
1. 下拉式菜单内容和要求按照Windows XP中的记事本的菜单编写。增加一个简易计算器功能。
2. 计算器实现简单的加、减、乘、除功能

Option Explicit
Dim e As String
Dim f As String
Dim op As String
Dim chk As Integer

Private Sub cmdAC_Click()
e = ""
f = ""
op = ""
txtDisp.Caption = "0"
End Sub

Private Sub cmdEq_Click()
If op = "" Then
e = str(-(Val(e)))
txtDisp.Caption = e
Else
f = str(-(Val(e)))
txtDisp.Caption = f
End If
chk = 1
End Sub

Private Sub cmdNum_Click(Index As Integer)
On Error GoTo eh2
If chk = 1 Then
e = ""
f = ""
op = ""
chk = 0
End If
If op = "" Then
e = str(Val(e & str(Index)))
txtDisp.Caption = e
Else
f = str(Val(f & str(Index)))
txtDisp.Caption = f
End If
Exit Sub
eh2:
txtDisp.Caption = "-E-"
e = ""
f = ""
op =