⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 计算器.frm

📁 包括式子计算和一般计算器功能。用栈实现式子计算功能
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Index           =   2
      Left            =   3840
      Picture         =   "计算器.frx":225F6
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   3720
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "÷"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   42
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Index           =   3
      Left            =   3840
      Picture         =   "计算器.frx":2270A
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   4560
      Width           =   1095
   End
   Begin VB.CommandButton Command7 
      Caption         =   "普通计算"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   0
      Left            =   240
      Picture         =   "计算器.frx":2281E
      Style           =   1  'Graphical
      TabIndex        =   4
      ToolTipText     =   "一般计算器功能"
      Top             =   0
      Width           =   1335
   End
   Begin VB.CommandButton Command7 
      BackColor       =   &H0000FF00&
      Caption         =   "式子计算"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   1
      Left            =   1800
      MaskColor       =   &H0080FF80&
      Picture         =   "计算器.frx":22A0F
      Style           =   1  'Graphical
      TabIndex        =   3
      ToolTipText     =   "输入一个式子计算结果"
      Top             =   0
      Width           =   1335
   End
   Begin VB.CommandButton Command8 
      Caption         =   "退格"
      Height          =   975
      Left            =   5400
      Picture         =   "计算器.frx":22C00
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "删除显示的最后一个字符"
      Top             =   1800
      Width           =   1935
   End
   Begin VB.CommandButton Command2 
      Caption         =   "平方"
      Height          =   735
      Index           =   4
      Left            =   5400
      Picture         =   "计算器.frx":22DF1
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   2880
      Width           =   1935
   End
   Begin VB.CommandButton Command3 
      Caption         =   "="
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   72
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1575
      Left            =   5400
      Picture         =   "计算器.frx":22FE2
      Style           =   1  'Graphical
      TabIndex        =   0
      ToolTipText     =   "计算结果"
      Top             =   3720
      Width           =   1935
   End
   Begin VB.Label Label2 
      BackColor       =   &H0080FFFF&
      Caption         =   "1.3版"
      ForeColor       =   &H00C0C000&
      Height          =   615
      Left            =   7800
      TabIndex        =   27
      Top             =   0
      Width           =   1215
   End
   Begin VB.Label Label1 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      BackStyle       =   0  'Transparent
      Caption         =   "TT:apple222888@163.com"
      ForeColor       =   &H0080FF80&
      Height          =   495
      Left            =   2160
      TabIndex        =   26
      Top             =   5400
      Width           =   5280
   End
End
Attribute VB_Name = "计算器"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a As String
Dim i, j, count1, count2 As Double
Dim n, count_doc As Integer



Private Sub Command1_Click(Index As Integer)
count1 = 0
If count2 = 0 Then
count_doc = 0
Text1.Text = ""
End If
If Text1.Text = "0" Then
Text1.Text = ""
ElseIf Text1.Text = "-0" Then
Text1.Text = "-"
End If
Select Case (Index)
Case 0
Text1.Text = Text1.Text + "0"
Case 1
Text1.Text = Text1.Text + "1"
Case 2
Text1.Text = Text1.Text + "2"
Case 3
Text1.Text = Text1.Text + "3"
Case 4
Text1.Text = Text1.Text + "4"
Case 5
Text1.Text = Text1.Text + "5"
Case 6
Text1.Text = Text1.Text + "6"
Case 7
Text1.Text = Text1.Text + "7"
Case 8
Text1.Text = Text1.Text + "8"
Case 9
Text1.Text = Text1.Text + "9"
Case 10

If Text1.Text = "" Then
Text1.Text = "0"
ElseIf Text1.Text = "-" Then
Text1.Text = "-0"
End If
If count_doc = 0 Then
Text1.Text = Text1.Text + "."
End If
count_doc = count_doc + 1

Case 11
If Text1.Text = "" Then
Text1.Text = "-"
End If
End Select


count2 = count2 + 1
a = Text1.Text
End Sub

Private Sub Command2_Click(Index As Integer)

If n <> 0 And count1 = 0 And n <> 5 Then
j = Val(a)

Select Case (n)
Case 1
Text1.Text = i + j
Case 2
Text1.Text = i - j
Case 3
Text1.Text = i * j
Case 4

If j = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
Else
Text1.Text = i / j
End If

End Select
If Val(Text1.Text) > -1 And Val(Text1.Text) < 0 Then
Text1.Text = "-0" & Abs(Text1.Text)
ElseIf Val(Text1.Text) > 0 And Val(Text1.Text) < 1 Then
Text1.Text = "0" & Text1.Text
End If

a = Text1.Text

End If

Select Case (Index)
Case 0
n = 1
Case 1
n = 2
Case 2
n = 3
Case 3
n = 4
Case 4
a = Val(Text1.Text) * Val(Text1.Text)
n = 6
If Val(a) > -1 And Val(a) < 0 Then
a = "-0" & Abs(a)
ElseIf Val(a) > 0 And Val(a) < 1 Then
a = "0" & a
End If


End Select
i = Val(a)

If Left(a, 2) = "-0" Then
If Mid(a, 3, 1) <> "." Then
a = "-" + Right(a, Len(a) - 2)
End If
ElseIf Left(a, 1) = "0" Then
If Mid(a, 2, 1) <> "." Then
a = Right(a, Len(a) - 1)
End If
End If
Text1.Text = a
count1 = count1 + 1
count2 = 0
Text2_Change
End Sub

Private Sub Command3_Click()
If count1 = 0 Then
j = Val(a)

Select Case (n)
Case 1
Text1.Text = i + j
Case 2
Text1.Text = i - j
Case 3
Text1.Text = i * j
Case 4

If j = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
Else
Text1.Text = i / j
End If

End Select

If Val(Text1.Text) > -1 And Val(Text1.Text) < 0 Then
Text1.Text = "-0" & Abs(Text1.Text)
ElseIf Val(Text1.Text) > 0 And Val(Text1.Text) < 1 Then
Text1.Text = "0" & Text1.Text
End If

End If


If Left(Text1.Text, 2) = "-0" Then
If Mid(Text1.Text, 3, 1) <> "." Then
Text1.Text = "-" + Right(Text1.Text, Len(Text1.Text) - 2)
End If
ElseIf Left(Text1.Text, 1) = "0" Then
If Mid(Text1.Text, 2, 1) <> "." Then
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
End If
End If

a = Text1.Text
n = 5
count2 = 0
Text2_Change
End Sub

Private Sub Command4_Click()
Text1.Text = "0"
count_doc = 0
n = 7
Text2_Change
End Sub

Private Sub Command5_Click()
Text1.Text = 0
n = 8
Text2_Change
a = 0
i = 0: j = 0
count1 = 0: count2 = 0: count_doc = 0
n = 0

End Sub

Private Sub Command6_Click()
End
End Sub

Private Sub Command7_Click(Index As Integer)
Select Case (Index)
Case 0
Case 1
Load 式子计算
式子计算.Show
Unload Me
End Select
End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub Command8_Click()
If a <> "" Then
If Right(a, 1) = "." Then
count_doc = count_doc - 1
End If
a = Left(a, Len(a) - 1)
End If
Text1.Text = a
End Sub

Private Sub Text2_Change()
Select Case (n)
Case 1
Text2.Text = "做加法"
Case 2
Text2.Text = "做减法"
Case 3
Text2.Text = "做乘法"
Case 4
Text2.Text = "做除法"
Case 5
Text2.Text = "结果"
Case 6
Text2.Text = "平方"
Case 7
Text2.Text = "清零"
Case 8
Text2.Text = "归零"

End Select
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -