怎样用VB设计简单计算器

2025-01-01 10:33:51
推荐回答(3个)
回答1:

Dim x As String
Private Sub Command1_Click()
Text1.Text = Text1.Text & "1"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text & "6"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text & "9"
End Sub
Private Sub Command12_Click()
If Label1.Caption = "+" Then
Text1.Text = Trim(Str(Val(x) + Val(Text1.Text)))
End If
If Label1.Caption = "-" Then
Text1.Text = Trim(Str(Val(x) - Val(Text1.Text)))
End If
If Label1.Caption = "*" Then
Text1.Text = Trim(Str(Val(x) * Val(Text1.Text)))
End If
If Label1.Caption = "/" Then
If Val(Text1.Text) = 0 Then
Text1.Text = "除数不能为零"
Else
If -1 < Val(x) / Val(Text1.Text) And Val(x) / Val(Text1.Text) < 0 Then
Text1.Text = Trim("-0" & Trim(Str(Abs(Val(x) / Val(Text1.Text)))))
Else
If 0 < Val(x) / Val(Text1.Text) And Val(x) / Val(Text1.Text) < 1 Then
Text1.Text = Trim("0" & Trim(Str(Val(x) / Val(Text1.Text))))
Else
Text1.Text = Trim(Str(Val(x) / Val(Text1.Text)))
End If
End If
End If
End If
End Sub
Private Sub Command13_Click()
x = Text1.Text
Text1.Text = ""
Label1.Caption = "+"
End Sub
Private Sub Command14_Click()
x = Text1.Text
Text1.Text = ""
Label1.Caption = "-"
End Sub
Private Sub Command15_Click()
x = Text1.Text
Text1.Text = ""
Label1.Caption = "*"
End Sub
Private Sub Command16_Click()
x = Text1.Text
Text1.Text = ""
Label1.Caption = "/"
End Sub
Private Sub Command17_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Command18_Click()
Unload Me
End Sub
Private Sub Command2_Click()
Text1.Text = Text1.Text & "4"
End Sub
Private Sub Command3_Click()
Text1.Text = Text1.Text & "7"
End Sub
Private Sub Command4_Click()
Text1.Text = Text1.Text & "0"
End Sub
Private Sub Command5_Click()
Text1.Text = Text1.Text & "2"
End Sub
Private Sub Command6_Click()
Text1.Text = Text1.Text & "5"
End Sub
Private Sub Command7_Click()
Text1.Text = Text1.Text & "8"
End Sub
Private Sub Command8_Click()
Text1.Text = Text1.Text & "."
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text & "3"
End Sub
Private Sub Form_Load()
Label1.Visible = False
End Sub

回答2:

主要掌握加减乘除平方开方几个函数的实用和寄存器变量的实用就行了或者百度一下因为简单计算器的代码比较简单很多网站都开放其源代码的

回答3:

你自己布置好界面,然后添加一些该用的控件,然后写代码,如果你不会就去网上搜,应该会有....我建意你还是自己学习一段时间在做,会好一些.....