如何用VB做一个简易计算器

来源:百度知道 编辑:UC知道 时间:2024/05/10 08:34:51

我自己写的(VB6.0),可以运行
现在还有一个小问题,就是当其他按钮拥有焦点时,按Enter不起等号的作用

Option Explicit

Dim ClearResult As Boolean '状态
Dim Operand As Double '操作数
Dim Operator As String '运算符

Private Sub CmdClear_Click() '清除结果
ClearResult = False
Operand = 0
txtResult.Text = "0"
CmdEqual.SetFocus
End Sub

Private Sub CmdDot_Click() '小数点
If ClearResult = True Then
txtResult.Text = "0"
ClearResult = False
End If
If txtResult.Text = "除数不能为零。" Then
Exit Sub
End If
If InStr(1, txtResult.Text, ".") Then
Exit Sub
Else
txtResult.Text = txtResult.Text + "."
End If
CmdEqual.SetFocus
End Sub

Private Sub CmdEqual_Click() '等号
On Error GoTo ErrHand:
If ClearResult = False Then
Select Case Operator
Ca