我的计算器有以下几个不足之处:
1,用键盘输入时,相应的按钮不能变成按下的样子.
2,键盘输入和鼠标点击时,光标不能总是停在最右边一位,从而使输入有误
3,不知道如何隐藏文本框中的光标.
4,文本框不是只读的.
控件属性设置和代码如下:
Dim Operand1 As Double, operand2 As Double
Dim Operator As String
Dim ClearDisplay As BooleanPrivate Sub Digits_Click(Index As Integer)
If ClearDisplay Then
Display.Caption = ""
ClearDisplay = False
End If
Display.Caption = Display.Caption & Digits(Index).Caption
End Sub
Private Sub DotBttn_Click()
If InStr(Display.Caption, ".") Then
Exit Sub
Else
Display.Caption = Display.Caption + "."
End If
End Sub
Private Sub Form_Load()End Sub'运算符
Private Sub Plus_Click()
Operand1 = Val(Display.Caption)
Operator = "+"
Display.Caption = " "
End Sub
Private Sub Minus_Click()
Operand1 = Val(Diplay.Caption)
Operator = "-"
Display.Caption = " "
End Sub
Private Sub Times_Click()
Operand1 = Val(Diplay.Caption)
Operator = "*"
Display.Caption = " "
End Sub
Private Sub Div_Click()
Operand1 = Val(Diplay.Caption)
Operator = "/"
Display.Caption = " "
End Sub'等号按钮
Private Sub Equals_Click()
Dim result As Double
On Error GoTo ErrorHandler
operand2 = Val(Display.Caption)
If Operator = "+" Then result = Operand1 + operand2
If Operator = "-" Then result = Operand1 - operand2
If Operator = "*" Then result = Operand1 * operand2
If Operator = "/" And operand2 <> 0 Then result = Operand1 / operand2
Display.Caption = result
ClearDisplay = True
GoTo Endsub
ErrorHandler:
MsgBox "此操作产生如下错误:" & vbCrLf & Err.descriprion
Display.Caption = "ERROR"
ClearDisplay = True
Endsub:
End Sub'正负数按钮:
Private Sub PlusMinus_Click()
Display.Caption = -Val(Display.Caption)
End Sub'倒数按钮
Private Sub Over_Click()
If Val(Display.Caption) <> 0 Then Display.Caption = 1 / Val(Display.Caption)
End Sub'清除按钮:
Private Sub Clear_Click()
Display.Caption = " "
End Sub
1,用键盘输入时,相应的按钮不能变成按下的样子.
2,键盘输入和鼠标点击时,光标不能总是停在最右边一位,从而使输入有误
3,不知道如何隐藏文本框中的光标.
4,文本框不是只读的.
控件属性设置和代码如下:
Dim Operand1 As Double, operand2 As Double
Dim Operator As String
Dim ClearDisplay As BooleanPrivate Sub Digits_Click(Index As Integer)
If ClearDisplay Then
Display.Caption = ""
ClearDisplay = False
End If
Display.Caption = Display.Caption & Digits(Index).Caption
End Sub
Private Sub DotBttn_Click()
If InStr(Display.Caption, ".") Then
Exit Sub
Else
Display.Caption = Display.Caption + "."
End If
End Sub
Private Sub Form_Load()End Sub'运算符
Private Sub Plus_Click()
Operand1 = Val(Display.Caption)
Operator = "+"
Display.Caption = " "
End Sub
Private Sub Minus_Click()
Operand1 = Val(Diplay.Caption)
Operator = "-"
Display.Caption = " "
End Sub
Private Sub Times_Click()
Operand1 = Val(Diplay.Caption)
Operator = "*"
Display.Caption = " "
End Sub
Private Sub Div_Click()
Operand1 = Val(Diplay.Caption)
Operator = "/"
Display.Caption = " "
End Sub'等号按钮
Private Sub Equals_Click()
Dim result As Double
On Error GoTo ErrorHandler
operand2 = Val(Display.Caption)
If Operator = "+" Then result = Operand1 + operand2
If Operator = "-" Then result = Operand1 - operand2
If Operator = "*" Then result = Operand1 * operand2
If Operator = "/" And operand2 <> 0 Then result = Operand1 / operand2
Display.Caption = result
ClearDisplay = True
GoTo Endsub
ErrorHandler:
MsgBox "此操作产生如下错误:" & vbCrLf & Err.descriprion
Display.Caption = "ERROR"
ClearDisplay = True
Endsub:
End Sub'正负数按钮:
Private Sub PlusMinus_Click()
Display.Caption = -Val(Display.Caption)
End Sub'倒数按钮
Private Sub Over_Click()
If Val(Display.Caption) <> 0 Then Display.Caption = 1 / Val(Display.Caption)
End Sub'清除按钮:
Private Sub Clear_Click()
Display.Caption = " "
End Sub
2,键盘输入和鼠标点击时,光标不能总是停在最右边一位,从而使输入有误,//不理解你说得输入有误
3,不知道如何隐藏文本框中的光标. //Enable=false就没光标了
4,文本框不是只读的. //文本框设置成只读
enable=false那文本框不是要不见了??