📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "计算器"
ClientHeight = 3705
ClientLeft = 4620
ClientTop = 1710
ClientWidth = 4785
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3705
ScaleWidth = 4785
Begin VB.CommandButton Command3
Caption = "<-"
Height = 375
Left = 3000
TabIndex = 23
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "+"
Height = 375
Index = 12
Left = 3000
TabIndex = 22
Top = 1380
Width = 615
End
Begin VB.CommandButton Command1
Caption = "-"
Height = 375
Index = 13
Left = 3840
TabIndex = 21
Top = 1380
Width = 615
End
Begin VB.CommandButton Command1
Caption = "x"
Height = 375
Index = 14
Left = 3000
TabIndex = 20
Top = 1800
Width = 615
End
Begin VB.CommandButton Command1
Caption = "÷"
Height = 375
Index = 15
Left = 3840
TabIndex = 19
Top = 1800
Width = 615
End
Begin VB.CommandButton Command1
Caption = "="
Height = 375
Index = 16
Left = 3000
TabIndex = 18
Top = 2220
Width = 615
End
Begin VB.CommandButton Command1
Caption = "CE"
Height = 375
Index = 17
Left = 3840
TabIndex = 17
Top = 960
Width = 615
End
Begin VB.CommandButton Command2
Caption = "X^2"
Height = 375
Left = 3840
TabIndex = 16
Top = 2220
Width = 615
End
Begin VB.CommandButton Command5
Caption = "√"
Height = 375
Left = 3000
TabIndex = 15
Top = 2640
Width = 615
End
Begin VB.CommandButton Command6
Caption = "int"
Height = 375
Left = 3840
TabIndex = 14
Top = 2640
Width = 615
End
Begin VB.CommandButton Command1
Caption = "±"
Height = 375
Index = 11
Left = 1680
TabIndex = 13
Top = 2640
Width = 615
End
Begin VB.CommandButton Command4
Caption = "&ON"
Height = 375
Left = 3720
TabIndex = 12
Top = 360
Width = 735
End
Begin VB.CommandButton Command1
Caption = "."
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 10
Left = 960
TabIndex = 11
Top = 2640
Width = 615
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 375
Index = 9
Left = 120
TabIndex = 10
Top = 2640
Width = 615
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 375
Index = 8
Left = 1680
TabIndex = 9
Top = 2100
Width = 615
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 375
Index = 7
Left = 900
TabIndex = 8
Top = 2100
Width = 615
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 375
Index = 6
Left = 120
TabIndex = 7
Top = 2100
Width = 615
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 375
Index = 5
Left = 1680
TabIndex = 6
Top = 1560
Width = 615
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 375
Index = 4
Left = 900
TabIndex = 5
Top = 1560
Width = 615
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 375
Index = 3
Left = 120
TabIndex = 4
Top = 1560
Width = 615
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 375
Index = 2
Left = 1680
TabIndex = 3
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 375
Index = 1
Left = 900
TabIndex = 2
Top = 960
Width = 615
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 375
Index = 0
Left = 120
TabIndex = 1
Top = 960
Width = 615
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 0
Text = " "
Top = 360
Width = 3495
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim x!, N1!, N2!
Dim StrN1$, StrN2$
Dim FirstN As Boolean
Dim PointFlag As Boolean
Dim Runsign As Integer
Dim SignFlag As Boolean
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 To 9
If FirstN Then
StrN1 = Str(Index)
FirstN = False
Else
StrN1 = StrN1 + Str(Index)
End If
Text1.Text = StrN1
Case 10
If Not PointFlag Then
If FirstN Then
StrN1 = "0."
FirstN = False
Else
StrN1 = StrN1 + "."
End If
Else
Exit Sub
End If
PointFlag = True
Text1.Text = StrN1
Case 11
If Sgn(Val(StrN1)) = 1 Then
StrN1 = Val("-" + StrN1)
Else
If Sgn(Val(StrN1)) = -1 Then
StrN1 = Val(Right(StrN1, Len(StrN1) - 1))
End If
StrN1 = ""
End If
Text1.Text = StrN1
Case 12 To 15
FirstN = True
PointFlag = False
If SignFlag Then
Call Run
Else
SignFlag = True
StrN2 = StrN1
StrN1 = ""
End If
Runsign = Index - 11
Case 12 To 15
FirstN = True
PointFlag = False
If SignFlag Then
Call Run
Else
SignFlag = True
StrN2 = StrN1
StrN1 = ""
End If
Runsign = Index - 11
Case 16
If Not SignFlag Then
Text1.Text = StrN1
Ysjg = Val(StrN1)
FirstN = True
PointFlag = False
Else
Call Run
SignFlag = False
End If
Case 17
N1 = 0
N2 = 0
StrN1 = ""
StrN2 = ""
FirstN = True
PointFlag = False
Runsign = 0
SignFlag = False
Text1.Text = ""
End Select
End Sub
Private Sub Command2_Click()
Text1.Text = Str(Val(Text1.Text) * Val(Text1.Text))
End Sub
Private Sub Command3_Click()
If Len(Text1.Text) > 1 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
Else
Text1.Text = ""
End If
End Sub
Private Sub Command4_Click()
If Command4.Caption = UCase("&off") Then
Command4.Caption = UCase("&on")
For i = 0 To 16
Command1(i).Enabled = False
Next i
Else
For i = 0 To 16
Command1(i).Enabled = True
Next i
Command4.Caption = UCase("&off")
End If
End Sub
Private Sub Command5_Click()
Text1.Text = Str(Sqr(Val(Text1.Text)))
End Sub
Private Sub Command6_Click()
Text1.Text = Str(Int(Val(Text1.Text)))
End Sub
Private Sub Form_Load()
N1 = 0: N2 = 0
StrN1 = "": StrN2 = ""
FirstN = True
PointFlag = False
Runsign = 0
SignFlag = False
End Sub
Public Sub Run()
Dim Ysjg As Single
N1 = Val(StrN2)
N2 = Val(StrN1)
Select Case Runsign
Case 1
Ysjg = N1 + N2
Case 2
Ysjg = N1 - N2
Case 3
Ysjg = N1 * N2
Case 4
If N2 <> 0 Then
Ysjg = N1 / N2
Else
MsgBox "注意!除数不能为0!", vbExclamation, "出错,注意"
End If
End Select
StrN2 = Str(Ysjg)
StrN1 = StrN2
Text1.Text = StrN2
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -