请帮我添加\修改一下代码,使计算器功能更为完整.
1\使计算器能在按数字键后显示在文本框中的是带有"."的数字,例如"9."
2\使计算器能在按等号键后的运算结果显示在文本框中的是带有"."的结果.
3\添加按小数点键功能的代码本人编写的代码:
Dim q As Integer
Dim a As String
Dim y As String
Dim x As String
Dim z As IntegerPrivate Sub Form_KeyPress(KeyAscii As Integer)
If q = 2 Then '按符号后再按数字,会发生清空
Text1.Text = ""
End If
Select Case KeyAscii
Case 48
If Text1.Text = "0." Then '按0时,会始终保持为0.
Text1.Text = "0."
Else
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
End If
Case 49
If Text1.Text = "0." Then '按数字1-9时,会发生清空
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 50
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 51
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 52
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 53
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 54
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 55
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 56
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 57
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 42
a = "*"
x = Text1.Text
q = 2
Case 43
a = "+"
x = Text1.Text
q = 2
Case 45
a = "-"
x = Text1.Text
q = 2
Case 47
a = "/"
x = Text1.Text
q = 2
Case 61 '等号
If a = "+" Then
If z = 3 Then
x = Text1.Text '第二次按等号
Else
y = Text1.Text '第一次按等号
End If
z = 3
Text1.Text = Val(x) + Val(y)
ElseIf a = "-" Then
If z = 3 Then
x = Text1.Text
Else
y = Text1.Text
End If
z = 3
Text1.Text = Val(x) - Val(y)
ElseIf a = "*" Then
If z = 3 Then
x = Text1.Text
Else
y = Text1.Text
End If
z = 3
Text1.Text = Val(x) * Val(y)
ElseIf a = "/" Then
If z = 3 Then
x = Text1.Text
Else
y = Text1.Text
End If
z = 3
Text1.Text = Val(x) / Val(y)
End If
End Select
End SubPrivate Sub Form_Load()
Text1.Text = "0."
z = 0
End Sub
1\使计算器能在按数字键后显示在文本框中的是带有"."的数字,例如"9."
2\使计算器能在按等号键后的运算结果显示在文本框中的是带有"."的结果.
3\添加按小数点键功能的代码本人编写的代码:
Dim q As Integer
Dim a As String
Dim y As String
Dim x As String
Dim z As IntegerPrivate Sub Form_KeyPress(KeyAscii As Integer)
If q = 2 Then '按符号后再按数字,会发生清空
Text1.Text = ""
End If
Select Case KeyAscii
Case 48
If Text1.Text = "0." Then '按0时,会始终保持为0.
Text1.Text = "0."
Else
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
End If
Case 49
If Text1.Text = "0." Then '按数字1-9时,会发生清空
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 50
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 51
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 52
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 53
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 54
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 55
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 56
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 57
If Text1.Text = "0." Then
Text1.Text = ""
End If
q = 1
Text1.Text = Text1.Text & Chr$(KeyAscii)
Case 42
a = "*"
x = Text1.Text
q = 2
Case 43
a = "+"
x = Text1.Text
q = 2
Case 45
a = "-"
x = Text1.Text
q = 2
Case 47
a = "/"
x = Text1.Text
q = 2
Case 61 '等号
If a = "+" Then
If z = 3 Then
x = Text1.Text '第二次按等号
Else
y = Text1.Text '第一次按等号
End If
z = 3
Text1.Text = Val(x) + Val(y)
ElseIf a = "-" Then
If z = 3 Then
x = Text1.Text
Else
y = Text1.Text
End If
z = 3
Text1.Text = Val(x) - Val(y)
ElseIf a = "*" Then
If z = 3 Then
x = Text1.Text
Else
y = Text1.Text
End If
z = 3
Text1.Text = Val(x) * Val(y)
ElseIf a = "/" Then
If z = 3 Then
x = Text1.Text
Else
y = Text1.Text
End If
z = 3
Text1.Text = Val(x) / Val(y)
End If
End Select
End SubPrivate Sub Form_Load()
Text1.Text = "0."
z = 0
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货