VB制作计算器,要求有加减乘除,清除退出,要写清楚
展开全部
粘贴到记事本,保存成 Form1.frm文件,用VB打开即可:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4065
ClientLeft = 60
ClientTop = 450
ClientWidth = 3885
LinkTopic = "Form1"
ScaleHeight = 4065
ScaleWidth = 3885
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "/"
Height = 495
Index = 3
Left = 2820
TabIndex = 17
Top = 2940
Width = 675
End
Begin VB.CommandButton Command2
Caption = "*"
Height = 495
Index = 2
Left = 2820
TabIndex = 16
Top = 2400
Width = 675
End
Begin VB.CommandButton Command2
Caption = "-"
Height = 495
Index = 1
Left = 2820
TabIndex = 15
Top = 1860
Width = 675
End
Begin VB.CommandButton Command2
Caption = "+"
Height = 495
Index = 0
Left = 2820
TabIndex = 14
Top = 1320
Width = 675
End
Begin VB.CommandButton Command3
Caption = "OFF"
Height = 495
Index = 1
Left = 2820
TabIndex = 13
Top = 600
Width = 675
End
Begin VB.CommandButton Command3
Caption = "AC"
Height = 495
Index = 2
Left = 1860
TabIndex = 12
Top = 2940
Width = 675
End
Begin VB.CommandButton Command3
Caption = "="
Height = 495
Index = 0
Left = 1140
TabIndex = 11
Top = 2940
Width = 675
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 495
Index = 9
Left = 1860
TabIndex = 10
Top = 2400
Width = 675
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 495
Index = 8
Left = 1140
TabIndex = 9
Top = 2400
Width = 675
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 495
Index = 7
Left = 420
TabIndex = 8
Top = 2400
Width = 675
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 495
Index = 6
Left = 1860
TabIndex = 7
Top = 1860
Width = 675
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 495
Index = 5
Left = 1140
TabIndex = 6
Top = 1860
Width = 675
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 495
Index = 4
Left = 420
TabIndex = 5
Top = 1860
Width = 675
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 495
Index = 3
Left = 1860
TabIndex = 4
Top = 1320
Width = 675
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 495
Index = 2
Left = 1140
TabIndex = 3
Top = 1320
Width = 675
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 495
Index = 1
Left = 420
TabIndex = 2
Top = 1320
Width = 675
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 495
Index = 0
Left = 420
TabIndex = 1
Top = 2940
Width = 675
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Height = 435
Left = 420
TabIndex = 0
Text = "Text1"
Top = 600
Width = 2115
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim X As Single, X1 As Single, X2 As Single
Dim FH As Integer
Private Sub Command1_Click(Index As Integer)
If FH > 0 Then
X2 = Index
Select Case FH
Case 1
X = X1 + X2
Case 2
X = X1 - X2
Case 3
X = X1 * X2
Case 4
X = X1 / X2
End Select
Else
X1 = Index
X = X1
End If
Text1 = Index
End Sub
Private Sub Command2_Click(Index As Integer)
X1 = X
FH = Index + 1
Text1 = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click(Index As Integer)
Select Case Index
Case 0
Text1 = X
X1 = X
FH = 0
Case 1
Unload Me
Case 2
X1 = 0
X2 = 0
X = 0
Text1 = ""
End Select
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4065
ClientLeft = 60
ClientTop = 450
ClientWidth = 3885
LinkTopic = "Form1"
ScaleHeight = 4065
ScaleWidth = 3885
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "/"
Height = 495
Index = 3
Left = 2820
TabIndex = 17
Top = 2940
Width = 675
End
Begin VB.CommandButton Command2
Caption = "*"
Height = 495
Index = 2
Left = 2820
TabIndex = 16
Top = 2400
Width = 675
End
Begin VB.CommandButton Command2
Caption = "-"
Height = 495
Index = 1
Left = 2820
TabIndex = 15
Top = 1860
Width = 675
End
Begin VB.CommandButton Command2
Caption = "+"
Height = 495
Index = 0
Left = 2820
TabIndex = 14
Top = 1320
Width = 675
End
Begin VB.CommandButton Command3
Caption = "OFF"
Height = 495
Index = 1
Left = 2820
TabIndex = 13
Top = 600
Width = 675
End
Begin VB.CommandButton Command3
Caption = "AC"
Height = 495
Index = 2
Left = 1860
TabIndex = 12
Top = 2940
Width = 675
End
Begin VB.CommandButton Command3
Caption = "="
Height = 495
Index = 0
Left = 1140
TabIndex = 11
Top = 2940
Width = 675
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 495
Index = 9
Left = 1860
TabIndex = 10
Top = 2400
Width = 675
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 495
Index = 8
Left = 1140
TabIndex = 9
Top = 2400
Width = 675
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 495
Index = 7
Left = 420
TabIndex = 8
Top = 2400
Width = 675
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 495
Index = 6
Left = 1860
TabIndex = 7
Top = 1860
Width = 675
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 495
Index = 5
Left = 1140
TabIndex = 6
Top = 1860
Width = 675
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 495
Index = 4
Left = 420
TabIndex = 5
Top = 1860
Width = 675
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 495
Index = 3
Left = 1860
TabIndex = 4
Top = 1320
Width = 675
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 495
Index = 2
Left = 1140
TabIndex = 3
Top = 1320
Width = 675
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 495
Index = 1
Left = 420
TabIndex = 2
Top = 1320
Width = 675
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 495
Index = 0
Left = 420
TabIndex = 1
Top = 2940
Width = 675
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Height = 435
Left = 420
TabIndex = 0
Text = "Text1"
Top = 600
Width = 2115
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim X As Single, X1 As Single, X2 As Single
Dim FH As Integer
Private Sub Command1_Click(Index As Integer)
If FH > 0 Then
X2 = Index
Select Case FH
Case 1
X = X1 + X2
Case 2
X = X1 - X2
Case 3
X = X1 * X2
Case 4
X = X1 / X2
End Select
Else
X1 = Index
X = X1
End If
Text1 = Index
End Sub
Private Sub Command2_Click(Index As Integer)
X1 = X
FH = Index + 1
Text1 = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click(Index As Integer)
Select Case Index
Case 0
Text1 = X
X1 = X
FH = 0
Case 1
Unload Me
Case 2
X1 = 0
X2 = 0
X = 0
Text1 = ""
End Select
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询