求VB设计的加减乘除计算器!!用
简易计算器,可以浮点运算,也许会对你有帮助。
在模块上设置0-9(index0-9),比如0设置为command0。(+ - * / 。)
原代码:
Dim value1 As Single ‘value是计算器第一次接收键盘的值
Dim value2 As Single ‘value是计算器第二次接收键盘的值
Dim operator As String
Dim result As Single
Dim isTime As...全部
简易计算器,可以浮点运算,也许会对你有帮助。
在模块上设置0-9(index0-9),比如0设置为command0。(+ - * / 。)
原代码:
Dim value1 As Single ‘value是计算器第一次接收键盘的值
Dim value2 As Single ‘value是计算器第二次接收键盘的值
Dim operator As String
Dim result As Single
Dim isTime As Boolean
Dim ClearDisplay As Boolean ‘显示设置为boolean
Private Sub Command_AC_Click() ‘返回键 0
ClearDisplay = False
Text1。
Text = "0"
ClearDisplay = True
End Sub
Private Sub Command_devide_Click()
value1 = Val(Text1。
Text)
Text1。Text = Text1。Text & "/"
operator = "/"
ClearDisplay = True
End Sub
Private Sub Command_dot_Click()
If InStr(Text1。
Text, "。") Then
Exit Sub
Else
Text1。Text = Text1。
Text & "。"
End If
End Sub
Private Sub Command_equal_Click()
value2 = Val(Text1。
Text)
ClearDisplay = False
If operator = "+" Then result = value1 + value2
Text1。
Text = result
If operator = "-" Then result = value1 - value2
Text1。
Text = result
If operator = "*" Then result = value1 * value2
Text1。
Text = result
If operator = "/" Then result = value1 / value2
Text1。
Text = result
End Sub
Private Sub Command_minus_Click()
value1 = Val(Text1。
Text)
Text1。Text = Text1。Text & "-"
operator = "-"
ClearDisplay = True
End Sub
Private Sub Command_multiply_Click()
value1 = Val(Text1。
Text)
Text1。Text = Text1。Text & "*"
operator = "*"
ClearDisplay = True
End Sub
Private Sub Command_plus_Click()
value1 = Val(Text1。
Text)
Text1。Text = Text1。Text & "+"
operator = "+"
ClearDisplay = True
End Sub
Private Sub Command_time_Click() ‘时间显示(在label1里)
If isTime = True Then
Label1。
Visible = True
isTime = False
Else
Label1。Visible = False
isTime = True
End If
End Sub
Private Sub Command0_Click()
If ClearDisplay = True Then ‘每输一个值,清屏
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command0。Caption
End Sub
Private Sub Command1_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command1。Caption
End Sub
Private Sub Command2_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command2。Caption
End Sub
Private Sub Command3_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command3。Caption
End Sub
Private Sub Command4_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command4。Caption
End Sub
Private Sub Command5_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command5。Caption
End Sub
Private Sub Command6_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command6。Caption
End Sub
Private Sub Command7_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command7。Caption
End Sub
Private Sub Command8_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command8。Caption
End Sub
Private Sub Command9_Click()
If ClearDisplay = True Then
Text1。
Text = ""
ClearDisplay = False
End If
Text1。
Text = Text1。Text + Command9。Caption
End Sub
Private Sub Form_Load()
ClearDisplay = False
Text1。
Text = "0"
ClearDisplay = True
End Sub
Private Sub Timer1_Timer() ‘附加功能:显示当前时间
Label1。
Caption = Time
End Sub
。收起