哪位高手能帮我编写一个VB计算器程序?
答案:1 悬赏:50
解决时间 2021-04-27 16:59
- 提问者网友:放荡不羁
- 2021-04-26 16:47
各路高手,小弟现在需要一份VB作业,是个计算器程序,用VB6.0版本,界面包括0~9十个数字键,+-*\=五个运算键,还有小数点,外加一个清除键,希望高手编程后把代码连同界面截图一起发给我,谢谢了~可以的话我给你我的邮箱,谢谢~
最佳答案
- 二级知识专家网友:何以畏孤独
- 2021-04-26 18:05
给LZ下面这个计算器程序吧
=检举Public a, b As Double
Public CalKey As String
Private Sub Form_Load()
Text1.Text = 0
End Sub
Private Sub Command1_Click(Index As Integer)
Text1.Text = Trim(Text1.Text)
If Text1.Text = "0" Then Text1.Text = ""
If Index <= 9 Then
Text1.Text = Text1.Text & Format(Index)
ElseIf Index = 10 Then
Text1.Text =
Text1.Text & "."
ElseIf Index = 11 Then
If Len(Text1.Text) >= 1 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
ElseIf Index = 12 Then
Text1.Text = 0
ElseIf Index = 13 Then
Text1.Text = -Val(Text1.Text)
End If
End Sub
Private Sub Command3_Click(Index As Integer)
a = Val(Text1.Text)
Select Case Index
Case 0
CalKey = "+"
Case 1
CalKey = "-"
Case 2
CalKey = "*"
Case 3
CalKey = "/"
Case 4
CalKey = "%"
Call Command4_Click
Case 5
CalKey = "sqr"
Call Command4_Click
Case 6
CalKey = "sin"
Call Command4_Click
Case 7
CalKey = "cos"
Call Command4_Click
End Select
If Index <= 3 Then
Text1.Text = ""
End If
End Sub
rivate Sub Command4_Click()
b = Val(Text1.Text)
Select Case CalKey
Case "+"
Text1.Text = a + b
Case "-"
Text1.Text = a - b
Case "*"
Text1.Text = a * b
Case "/"
If b <> 0 Then
Text1.Text = a / b
Else
Text1.Text = ""
MsgBox "除数不能为0"
End If
Case "%"
Text1.Text = a / 100#
Case "sqr"
If a >= 0 Then
Text1.Text = Sqr(a)
Else
Text1.Text = ""
MsgBox "二次方根,输入数不能小于0"
End If
Case "sin"
If a >= -1 And a <= 1 Then
Text1.Text = Sin(a)
Else
Text1.Text = ""
MsgBox "正弦函数,输入数应介于[-1, 1]之间"
End If
Case "cos"
If a >= -1 And a <= 1 Then
Text1.Text = Cos(a)
Else
Text1.Text = ""
MsgBox "余弦函数,输入数应介于[-1, 1]之间"
End If
End Select
If Left(Text1.Text, 1) = "." Then
Text1.Text = "0" & Text1.Text
End Sub
Private Sub Command5_Click()
Unload Me
End Sub
=检举Public a, b As Double
Public CalKey As String
Private Sub Form_Load()
Text1.Text = 0
End Sub
Private Sub Command1_Click(Index As Integer)
Text1.Text = Trim(Text1.Text)
If Text1.Text = "0" Then Text1.Text = ""
If Index <= 9 Then
Text1.Text = Text1.Text & Format(Index)
ElseIf Index = 10 Then
Text1.Text =
Text1.Text & "."
ElseIf Index = 11 Then
If Len(Text1.Text) >= 1 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
ElseIf Index = 12 Then
Text1.Text = 0
ElseIf Index = 13 Then
Text1.Text = -Val(Text1.Text)
End If
End Sub
Private Sub Command3_Click(Index As Integer)
a = Val(Text1.Text)
Select Case Index
Case 0
CalKey = "+"
Case 1
CalKey = "-"
Case 2
CalKey = "*"
Case 3
CalKey = "/"
Case 4
CalKey = "%"
Call Command4_Click
Case 5
CalKey = "sqr"
Call Command4_Click
Case 6
CalKey = "sin"
Call Command4_Click
Case 7
CalKey = "cos"
Call Command4_Click
End Select
If Index <= 3 Then
Text1.Text = ""
End If
End Sub
rivate Sub Command4_Click()
b = Val(Text1.Text)
Select Case CalKey
Case "+"
Text1.Text = a + b
Case "-"
Text1.Text = a - b
Case "*"
Text1.Text = a * b
Case "/"
If b <> 0 Then
Text1.Text = a / b
Else
Text1.Text = ""
MsgBox "除数不能为0"
End If
Case "%"
Text1.Text = a / 100#
Case "sqr"
If a >= 0 Then
Text1.Text = Sqr(a)
Else
Text1.Text = ""
MsgBox "二次方根,输入数不能小于0"
End If
Case "sin"
If a >= -1 And a <= 1 Then
Text1.Text = Sin(a)
Else
Text1.Text = ""
MsgBox "正弦函数,输入数应介于[-1, 1]之间"
End If
Case "cos"
If a >= -1 And a <= 1 Then
Text1.Text = Cos(a)
Else
Text1.Text = ""
MsgBox "余弦函数,输入数应介于[-1, 1]之间"
End If
End Select
If Left(Text1.Text, 1) = "." Then
Text1.Text = "0" & Text1.Text
End Sub
Private Sub Command5_Click()
Unload Me
End Sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯