答案:Private Sub Command1_Click(Index As Integer) '0-9数字键
Text1.Text = Text1.Text & Index
Text1.SetFocus
End Sub
Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer) '阻止键盘输入,不过不知为什么没有用
KeyAscii = 0
End Sub
Private Sub Command2_Click(Index As Integer) ' "."键
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command3_Click() '退格键
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command4_Click() '清除键
Text1.Text = ""
End Sub
Private Sub Command5_Click(Index As Integer) '做运算,总觉得逻辑上哪有问题
shu1 = Val(Text1.Text)
process = shu1
Text1.Text = ""
If judge = Command5(0) Then
process0 = shu1 + Command(0)
ElseIf judge = Command5(1) Then
process1 = shu1 + Command5(1)
ElseIf judge = Command5(2) Then
process2 = shu1 + Command(2)
ElseIf judge = Command5(3) Then
process3 = shu1 + Command5(3)
End If
shu2 = Val(Text1.Text)
End Sub
Private Sub Command6_Click() '等号
result = process + shu2
Text1.Text = result
If process0 Then
result = shu1 + shu2
ElseIf process1 Then
result = shu1 - shu2
ElseIf process2 Then
result = shu1 * shu2
ElseIf process3 Then
result = shu1 / shu2
End If
End Sub
Private Sub Text1_Change()
If judge = False Then
shu2 = Val(Text1.Text)
End If
Text1.SetFocus
End Sub
这个好像并不难啊
1、设计计算器版面
2、对每个按钮添加响应事件
3、获取结果(当点击到运算符的时候获取前面输入的数据)
4、最后根据运算符运算输出结果
上一个:VB中与Print有关的函数有哪些
下一个:VB数据库里面用data查找数据怎么弄