求大佬设计用VB帮设计个计算器

zys873584836 2020-06-17 10:18:23
设计计算器界面,实现计算器相应功能(按多功能计算器进行设计),并且能够在一个文本框内能实现两个数的加减乘除。
...全文
464 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZHRXJR 2020-08-28
  • 打赏
  • 举报
回复
最简单的计算器:

Dim YS1 As Single, YS2 As Single, YSJG As Single, YSF As String, HDS As Single

Private Sub Command1_Click(Index As Integer)
If HDS <> 0 Then YSF = "": YS1 = 0: YS2 = 0: HDS = 0: Text1.Text = ""
If YS1 <> 0 And YSF <> "" And YS2 <> 0 Then YS1 = 0: YSH = "": YS2 = 0: Text1.Text = ""
Select Case Index
    Case 0: Text1.Text = Text1.Text & Command1(0).Caption
    Case 1: Text1.Text = Text1.Text & Command1(1).Caption
    Case 2: Text1.Text = Text1.Text & Command1(2).Caption
    Case 3: Text1.Text = Text1.Text & Command1(3).Caption
    Case 4: Text1.Text = Text1.Text & Command1(4).Caption
    Case 5: Text1.Text = Text1.Text & Command1(5).Caption
    Case 6: Text1.Text = Text1.Text & Command1(6).Caption
    Case 7: Text1.Text = Text1.Text & Command1(7).Caption
    Case 8: Text1.Text = Text1.Text & Command1(8).Caption
    Case 9: Text1.Text = Text1.Text & Command1(9).Caption
    Case 10:
        If Left(Text1.Text, 1) = "-" Then
        Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
        Else
        Text1.Text = "-" & Text1.Text
        End If
    Case 11: Text1.Text = Text1.Text & Command1(11).Caption
End Select
End Sub

Private Sub Command2_Click(Index As Integer)
If Index = 0 Then   '+
YSF = "+"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 1 Then   '-
YSF = "-"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 2 Then   '*
YSF = "*"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 3 Then    '/
YSF = "/"
YS1 = Val(Text1.Text)
Text1.Text = ""
ElseIf Index = 4 Then   '=
YS2 = Val(Text1.Text)
    If YS2 = 0 Then
        MsgBox "你没有输入第二个运算数,请输入", 16, "错误提示!"
        Exit Sub
    End If
    Select Case YSF
        Case "+": Text1.Text = YS1 + YS2
        Case "-": Text1.Text = YS1 - YS2
        Case "*": Text1.Text = YS1 * YS2
        Case "/": Text1.Text = YS1 / YS2
    End Select
'YSF = "": YS1 = 0: YS2 = 0
End If
End Sub

Private Sub Command6_Click()
'AC
Text1.Text = ""
YSF = "": YS1 = 0: YS2 = 0
End Sub

Private Sub Form_Load()
Text1.Text = ""
YSF = "": YS1 = 0: YS2 = 0
End Sub
threenewbee 2020-08-26
  • 打赏
  • 举报
回复
https://download.csdn.net/download/cjl20090909/2974829
https://download.csdn.net/download/gouyue/1418932
天中云雾 2020-08-04
  • 打赏
  • 举报
回复



Private Sub 按钮0_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 0
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 0
End If
End If
End Sub

Private Sub 按钮1_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 1
End If
If Val(Label1) = 0 Then
Label1.Caption = 1
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 1
End If
If Val(Label3) = 0 Then
Label3.Caption = 1
End If
End If
End Sub

Private Sub 按钮2_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 2
End If
If Val(Label1) = 0 Then
Label1.Caption = 2
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 2
End If
If Val(Label3) = 0 Then
Label3.Caption = 2
End If
End If
End Sub

Private Sub 按钮3_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 3
End If
If Val(Label1) = 0 Then
Label1.Caption = 3
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 3
End If
If Val(Label3) = 0 Then
Label3.Caption = 3
End If
End If
End Sub


Private Sub 按钮4_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 4
End If
If Val(Label1) = 0 Then
Label1.Caption = 4
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 4
End If
If Val(Label3) = 0 Then
Label3.Caption = 4
End If
End If
End Sub

Private Sub 按钮5_Click(Index As Integer)
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 5
End If
If Val(Label1) = 0 Then
Label1.Caption = 5
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 5
End If
If Val(Label3) = 0 Then
Label3.Caption = 5
End If
End If
End Sub

Private Sub 按钮6_Click(Index As Integer)
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 6
End If
If Val(Label1) = 0 Then
Label1.Caption = 6
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 6
End If
If Val(Label3) = 0 Then
Label3.Caption = 6
End If
End If
End Sub

Private Sub 按钮7_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 7
End If
If Val(Label1) = 0 Then
Label1.Caption = 7
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 7
End If
If Val(Label3) = 0 Then
Label3.Caption = 7
End If
End If
End Sub

Private Sub 按钮8_Click()
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 8
End If
If Val(Label1) = 0 Then
Label1.Caption = 8
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 8
End If
If Val(Label3) = 0 Then
Label3.Caption = 8
End If
End If
End Sub

Private Sub 按钮9_Click(Index As Integer)
If Val(Text1) = 1 Then
If Val(Label1) <> 0 Then
Label1.Caption = Val(Label1) & 9
End If
If Val(Label1) = 0 Then
Label1.Caption = 9
End If
End If
If Val(Text1) = 2 Then
If Val(Label3) <> 0 Then
Label3.Caption = Val(Label3) & 9
End If
If Val(Label3) = 0 Then
Label3.Caption = 9
End If
End If
End Sub

Private Sub 乘_Click()
Label2.Caption = "×"
Label8.Caption = 3
End Sub

Private Sub 除_Click()
Label2.Caption = "÷"
Label8.Caption = 4
End Sub

Private Sub 等于_Click()
If Val(Label8.Caption) = 1 Then Label5.Caption = Val(Label1) + Val(Label3)
If Val(Label8.Caption) = 2 Then Label5.Caption = Val(Label1) - Val(Label3)
If Val(Label8.Caption) = 3 Then Label5.Caption = Val(Label1) * Val(Label3)
If Val(Label8.Caption) = 4 Then
If Val(Label3) = 0 Then
MsgBox "除数不可以为零"
End If
If Val(Label3) <> 0 Then Label5.Caption = Val(Label1) / Val(Label3)
a = Len(Label5.Caption) - 1
If Left(Label5.Caption, 1) = "." Then
Label5.Caption = 0 & Left(Label5.Caption, 1) & Right(Label5.Caption, a)
End If
End If
End Sub

Private Sub 加_Click()
Label2.Caption = "+"
Label8.Caption = 1
End Sub

Private Sub 减_Click()
Label2.Caption = "-"
Label8.Caption = 2
End Sub


Private Sub 删除_Click()
If Val(Text1) = 1 Then
If Len(Label1.Caption) = 1 Then
Label1.Caption = 0
Else
Label9.Caption = Len(Label1.Caption) - 1
Label1.Caption = Left(Label1.Caption, Label9.Caption)
End If
End If
If Val(Text1) = 2 Then
If Len(Label3.Caption) = 1 Then
Label3.Caption = 0
Else
Label9.Caption = Len(Label3.Caption) - 1
Label3.Caption = Left(Label3.Caption, Label9.Caption)
End If
End If
End Sub
天中云雾 2020-08-04
  • 打赏
  • 举报
回复
Private Sub 按钮0_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 0 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 0 End If End If End Sub Private Sub 按钮1_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 1 End If If Val(Label1) = 0 Then Label1.Caption = 1 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 1 End If If Val(Label3) = 0 Then Label3.Caption = 1 End If End If End Sub Private Sub 按钮2_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 2 End If If Val(Label1) = 0 Then Label1.Caption = 2 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 2 End If If Val(Label3) = 0 Then Label3.Caption = 2 End If End If End Sub Private Sub 按钮3_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 3 End If If Val(Label1) = 0 Then Label1.Caption = 3 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 3 End If If Val(Label3) = 0 Then Label3.Caption = 3 End If End If End Sub Private Sub 按钮4_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 4 End If If Val(Label1) = 0 Then Label1.Caption = 4 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 4 End If If Val(Label3) = 0 Then Label3.Caption = 4 End If End If End Sub Private Sub 按钮5_Click(Index As Integer) If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 5 End If If Val(Label1) = 0 Then Label1.Caption = 5 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 5 End If If Val(Label3) = 0 Then Label3.Caption = 5 End If End If End Sub Private Sub 按钮6_Click(Index As Integer) If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 6 End If If Val(Label1) = 0 Then Label1.Caption = 6 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 6 End If If Val(Label3) = 0 Then Label3.Caption = 6 End If End If End Sub Private Sub 按钮7_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 7 End If If Val(Label1) = 0 Then Label1.Caption = 7 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 7 End If If Val(Label3) = 0 Then Label3.Caption = 7 End If End If End Sub Private Sub 按钮8_Click() If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 8 End If If Val(Label1) = 0 Then Label1.Caption = 8 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 8 End If If Val(Label3) = 0 Then Label3.Caption = 8 End If End If End Sub Private Sub 按钮9_Click(Index As Integer) If Val(Text1) = 1 Then If Val(Label1) <> 0 Then Label1.Caption = Val(Label1) & 9 End If If Val(Label1) = 0 Then Label1.Caption = 9 End If End If If Val(Text1) = 2 Then If Val(Label3) <> 0 Then Label3.Caption = Val(Label3) & 9 End If If Val(Label3) = 0 Then Label3.Caption = 9 End If End If End Sub Private Sub 乘_Click() Label2.Caption = "×" Label8.Caption = 3 End Sub Private Sub 除_Click() Label2.Caption = "÷" Label8.Caption = 4 End Sub Private Sub 等于_Click() If Val(Label8.Caption) = 1 Then Label5.Caption = Val(Label1) + Val(Label3) If Val(Label8.Caption) = 2 Then Label5.Caption = Val(Label1) - Val(Label3) If Val(Label8.Caption) = 3 Then Label5.Caption = Val(Label1) * Val(Label3) If Val(Label8.Caption) = 4 Then If Val(Label3) = 0 Then MsgBox "除数不可以为零" End If If Val(Label3) <> 0 Then Label5.Caption = Val(Label1) / Val(Label3) a = Len(Label5.Caption) - 1 If Left(Label5.Caption, 1) = "." Then Label5.Caption = 0 & Left(Label5.Caption, 1) & Right(Label5.Caption, a) End If End If End Sub Private Sub 加_Click() Label2.Caption = "+" Label8.Caption = 1 End Sub Private Sub 减_Click() Label2.Caption = "-" Label8.Caption = 2 End Sub Private Sub 删除_Click() If Val(Text1) = 1 Then If Len(Label1.Caption) = 1 Then Label1.Caption = 0 Else Label9.Caption = Len(Label1.Caption) - 1 Label1.Caption = Left(Label1.Caption, Label9.Caption) End If End If If Val(Text1) = 2 Then If Len(Label3.Caption) = 1 Then Label3.Caption = 0 Else Label9.Caption = Len(Label3.Caption) - 1 Label3.Caption = Left(Label3.Caption, Label9.Caption) End If End If End Sub
生存战争 2020-07-05
  • 打赏
  • 举报
回复
记得我之前也做了个计算器,不知道放哪了。。。。
脆皮大雪糕 2020-06-19
  • 打赏
  • 举报
回复
随便百度一下,遍地是这种代码

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧