用数字逻辑电路知识设计简易加减计算器
发布网友
发布时间:2022-04-24 17:52
我来回答
共1个回答
热心网友
时间:2023-10-28 12:06
Option Explicit
Private Sub Command1_Click()
Unload mnu(1)
End Sub
Private Sub Form_Load()
mnu(0).Caption = "chengfang"
mnu(0).Visible = True
Load mnu(1)
mnu(1).Caption = "lifang"
mnu(1).Visible = True
Load mnu(2)
mnu(2).Caption = "n次方"
mnu(2).Visible = True
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
mnuw.PopupMenu mnuc
End If
End Sub
Private Sub mnu_Click(Index As Integer)
Dim i As Integer
If Index = 0 Then
Label2.Caption = "^2"
Text3.Text = Val(Text1.Text) * Val(Text1.Text)
ElseIf Index = 1 Then
Label2.Caption = "^3"
Text3.Text = Val(Text1.Text) * Val(Text1.Text) * Val(Text1.Text)
ElseIf Index = 2 Then
Label2.Caption = "^" & Text2.Text
Text3.Text = Val(Text1.Text) ^ Val(Text2.Text)
End If
End Sub
Private Sub mnudev_Click()
Label2.Caption = "/"
On Error GoTo errlable '错误语句
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
Exit Sub
errlable:
MsgBox Err.Number & Err.Description
Text2.Text = ""
Text2.SetFocus
End Sub
Private Sub mnuexit_Click()
End
End Sub
Private Sub mnuplus_Click()
Label2.Caption = "-"
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
End Sub
Private Sub mnusub_Click()
Label2.Caption = "+"
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub mulit_Click()
Label2.Caption = "*"
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
If Button.Index = "1" Then
mnusub_Click
ElseIf Button.Index = "2" Then
mnuplus_Click
ElseIf Button.Index = "3" Then
mulit_Click
ElseIf Button.Index = "4" Then
mnudev_Click
ElseIf Button.Index = "5" Then
Label2.Caption = "^" & Text2.Text
Text3.Text = Val(Text1.Text) ^ Val(Text2.Text)
End If
End Sub
Function ErrorProgram(s As String) As Integer
Select Case s
Case 11
Print "0"
Case 55
Print "file is open"
End Select
End Function