已阅 狗屁不通:(VB)设计一个简单的加减法计算器,输入两个数,然后选择所需的运算符“+”或“-”,

来源:百度文库 编辑:高考问答 时间:2024/05/12 00:40:57
其结果显示在一个文本框中
我的邮箱是uxning@sina.com

这是一个带菜单的,可以用鼠标右键,你要的话我给你发过去,我的mail: fudi850@163.com
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

哈哈.简单!!

怎么发给你?