计算器'复制下列代码到记事本,保存为"Form1.frm" '用VB打开改文件,运行VERSION 5.00 Begin VB.Form Form1 BorderStyle = 1 'Fixed Single Caption = "Calc" ClientHeight = 3195 ClientLeft = 45 ClientTop = 330 ClientWidth = 3495 LinkTopic = "Form1" LockControls = -1 'True MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 3195 ScaleWidth = 3495 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton CommandOperator Height = 465 Index = 4 Left = 2490 TabIndex = 15 Top = 2370 Width = 645 End Begin VB.CommandButton CommandOperator Height = 465 Index = 3 Left = 2490 TabIndex = 14 Top = 1830 Width = 645 End Begin VB.CommandButton CommandOperator Height = 465 Index = 2 Left = 2490 TabIndex = 13 Top = 1260 Width = 645 End Begin VB.CommandButton CommandOperator Height = 465 Index = 1 Left = 2490 TabIndex = 12 Top = 720 Width = 645 End Begin VB.CommandButton CommandOperator Height = 465 Index = 0 Left = 1020 TabIndex = 11 Top = 2370 Width = 1365 End Begin VB.CommandButton CommandButton Height = 465 Index = 9 Left = 1740 TabIndex = 10 Top = 1830 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 8 Left = 1020 TabIndex = 9 Top = 1830 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 7 Left = 300 TabIndex = 8 Top = 1830 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 6 Left = 1740 TabIndex = 7 Top = 1260 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 5 Left = 1020 TabIndex = 6 Top = 1260 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 4 Left = 300 TabIndex = 5 Top = 1260 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 3 Left = 1740 TabIndex = 4 Top = 720 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 2 Left = 1020 TabIndex = 3 Top = 720 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 1 Left = 300 TabIndex = 2 Top = 720 Width = 645 End Begin VB.CommandButton CommandButton Height = 465 Index = 0 Left = 300 TabIndex = 1 Top = 2370 Width = 645 End Begin VB.TextBox Text1 Alignment = 1 'Right Justify Height = 285 Left = 300 Locked = -1 'True TabIndex = 0 Text = "0" Top = 300 Width = 2865 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option ExplicitDim Num As Long Dim Operator As Long Dim Reset As BooleanPrivate Sub Form_Load()
With Form1 .Left = (Screen.Width - .Width) / 2 .Top = (Screen.Height - .Height) / 2 End With
Dim i As Long For i = 0 To 9 CommandButton(i).Caption = CStr(i) Next i
End SubPrivate Sub CommandButton_Click(Index As Integer) If Reset = True Then Text1.Text = "0" Reset = False End If Text1.Text = Val(Text1.Text & Index) End SubPrivate Sub CommandOperator_Click(Index As Integer) Select Case Index Case 0 Select Case Operator Case 1 Text1.Text = Num + Val(Text1.Text) Case 2 Text1.Text = Num - Val(Text1.Text) Case 3 Text1.Text = Num * Val(Text1.Text) Case 4 Text1.Text = Num / Val(Text1.Text) End Select Num = 0 Operator = 0 Reset = True Case 1, 2, 3, 4 Num = Val(Text1.Text) Text1.Text = "0" Operator = Index End Select End Sub
'用VB打开改文件,运行VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Calc"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 3495
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 3495
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton CommandOperator
Height = 465
Index = 4
Left = 2490
TabIndex = 15
Top = 2370
Width = 645
End
Begin VB.CommandButton CommandOperator
Height = 465
Index = 3
Left = 2490
TabIndex = 14
Top = 1830
Width = 645
End
Begin VB.CommandButton CommandOperator
Height = 465
Index = 2
Left = 2490
TabIndex = 13
Top = 1260
Width = 645
End
Begin VB.CommandButton CommandOperator
Height = 465
Index = 1
Left = 2490
TabIndex = 12
Top = 720
Width = 645
End
Begin VB.CommandButton CommandOperator
Height = 465
Index = 0
Left = 1020
TabIndex = 11
Top = 2370
Width = 1365
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 9
Left = 1740
TabIndex = 10
Top = 1830
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 8
Left = 1020
TabIndex = 9
Top = 1830
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 7
Left = 300
TabIndex = 8
Top = 1830
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 6
Left = 1740
TabIndex = 7
Top = 1260
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 5
Left = 1020
TabIndex = 6
Top = 1260
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 4
Left = 300
TabIndex = 5
Top = 1260
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 3
Left = 1740
TabIndex = 4
Top = 720
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 2
Left = 1020
TabIndex = 3
Top = 720
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 1
Left = 300
TabIndex = 2
Top = 720
Width = 645
End
Begin VB.CommandButton CommandButton
Height = 465
Index = 0
Left = 300
TabIndex = 1
Top = 2370
Width = 645
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Height = 285
Left = 300
Locked = -1 'True
TabIndex = 0
Text = "0"
Top = 300
Width = 2865
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitDim Num As Long
Dim Operator As Long
Dim Reset As BooleanPrivate Sub Form_Load()
With Form1
.Left = (Screen.Width - .Width) / 2
.Top = (Screen.Height - .Height) / 2
End With
Dim i As Long
For i = 0 To 9
CommandButton(i).Caption = CStr(i)
Next i
CommandOperator(0).Caption = "="
CommandOperator(1).Caption = "+"
CommandOperator(2).Caption = "-"
CommandOperator(3).Caption = "*"
CommandOperator(4).Caption = "/"
End SubPrivate Sub CommandButton_Click(Index As Integer)
If Reset = True Then
Text1.Text = "0"
Reset = False
End If
Text1.Text = Val(Text1.Text & Index)
End SubPrivate Sub CommandOperator_Click(Index As Integer)
Select Case Index
Case 0
Select Case Operator
Case 1
Text1.Text = Num + Val(Text1.Text)
Case 2
Text1.Text = Num - Val(Text1.Text)
Case 3
Text1.Text = Num * Val(Text1.Text)
Case 4
Text1.Text = Num / Val(Text1.Text)
End Select
Num = 0
Operator = 0
Reset = True
Case 1, 2, 3, 4
Num = Val(Text1.Text)
Text1.Text = "0"
Operator = Index
End Select
End Sub
PS:没什么好鄙视的!!!.我又不打算朝VB方向走!!仅仅是老师要作业!~
程序来源:VB爱好者乐园
-----------------------------