怎么用VB编写四则运算计算器

来源:百度知道 编辑:UC知道 时间:2024/05/17 03:09:55
谢谢

试试这个~

Private Sub Command1_Click()
Label1 = Val(Text1) + Val(Text2)
End Sub
Private Sub Command2_Click()
Label1 = Val(Text1) - Val(Text2)
End Sub
Private Sub Command3_Click()
Label1 = Val(Text1) * Val(Text2)
End Sub
Private Sub Command4_Click()
If Val(Text2) <> 0 Then
Label1 = Val(Text1) / Val(Text2)
Else
MsgBox "除数不能为0"
Text2 = ""
Text2.SetFocus
End If
End Sub

http://post.baidu.com/f?kz=209715785我的计算器Option Explicit Dim FocusText As VB.TextBox Dim pd As Boolean Dim x As Double Dim y As Double Dim ch As Integer Private Sub Command1_Click(Index As Integer) On Error Resume Next FocusText.SetFocus If Index SendKeys Index ElseIf Index = 10 Then ch = Index - 10 x = Val(Text1.Text) Text1.Text = "" ElseIf Index = 14 Then y = Val(Text1.Text) Select Case ch Case 0 Text1.Text = x + y Case 1 Text1.Text = x - y Case 2 Text1.Text = x * y Ca