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

📄 式子计算.frm

📁 包括式子计算和一般计算器功能。用栈实现式子计算功能
💻 FRM
📖 第 1 页 / 共 2 页
字号:
      Caption         =   "1"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Index           =   1
      Left            =   360
      Picture         =   "式子计算.frx":29127
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   3720
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "0"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Index           =   0
      Left            =   360
      Picture         =   "式子计算.frx":291C7
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   4680
      Width           =   2055
   End
   Begin VB.TextBox Text1 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00C0FFFF&
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   42
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   240
      Locked          =   -1  'True
      TabIndex        =   0
      Top             =   600
      Width           =   8415
   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            =   1560
      TabIndex        =   26
      Top             =   5400
      Width           =   5280
   End
   Begin VB.Label Label2 
      BackColor       =   &H0080FFFF&
      Caption         =   "1.3版"
      ForeColor       =   &H00C0C000&
      Height          =   615
      Left            =   7800
      TabIndex        =   25
      Top             =   0
      Width           =   1215
   End
End
Attribute VB_Name = "式子计算"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a, b, c As Double
Dim s1, s2, s3 As String '算术符
Dim s1_1, s2_2, s3_3 As Integer '优先级
Dim temp1, temp2, temp3, temp As String
Dim count_equ, count1, count2, count_doc As Integer '数字跟算术符的计数



Private Sub Command1_Click(Index As Integer)

If count2 = 0 Then
count_doc = 0
End If

If count2 = 0 Then
temp = ""
End If

If Text1.Text = "0" Then
Text1.Text = ""
End If

If count_equ = 1 Then
Command5_Click
End If

'Text1.Text = Text1.Text + Command1(Index).Caption  '输入数字
Select Case (Index)
Case 0
Text1.Text = Text1.Text + "0"
temp = temp + "0"
Case 1
Text1.Text = Text1.Text + "1"
temp = temp + "1"
Case 2
Text1.Text = Text1.Text + "2"
temp = temp + "2"
Case 3
Text1.Text = Text1.Text + "3"
temp = temp + "3"
Case 4
Text1.Text = Text1.Text + "4"
temp = temp + "4"
Case 5
Text1.Text = Text1.Text + "5"
temp = temp + "5"
Case 6
Text1.Text = Text1.Text + "6"
temp = temp + "6"
Case 7
Text1.Text = Text1.Text + "7"
temp = temp + "7"
Case 8
Text1.Text = Text1.Text + "8"
temp = temp + "8"
Case 9
Text1.Text = Text1.Text + "9"
temp = temp + "9"
Case 10

If Text1.Text = "" Then
Text1.Text = "0"
End If
If count_doc = 0 Then
Text1.Text = Text1.Text + "."
temp = temp + "."
End If
count_doc = count_doc + 1
End Select

count2 = count2 + 1
End Sub

Private Sub Command2_Click(Index As Integer)

If count2 = 0 Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
GoTo retry
End If

count1 = count1 + 1

Select Case (count1)

Case 1

temp1 = temp
a = Val(temp1)

Case 2

temp2 = temp
b = Val(temp2)

Case 3


temp3 = temp

c = Val(temp3)

End Select

retry:
Select Case (Index)
Case 0
Text1.Text = Text1.Text + "+"
Case 1
Text1.Text = Text1.Text + "-"
Case 2
Text1.Text = Text1.Text + "*"
Case 3
Text1.Text = Text1.Text + "/"
End Select

'修改中,处理符号问题
If count1 = 1 Then
s1 = Right(Text1.Text, 1)
If s1 = "+" Or s1 = "-" Then
s1_1 = 1
ElseIf s1 = "*" Or s1 = "/" Then
s1_1 = 2
End If
ElseIf count1 = 2 Then
s2 = Right(Text1.Text, 1)
If s2 = "+" Or s2 = "-" Then
s2_2 = 1
ElseIf s2 = "*" Or s2 = "/" Then
s2_2 = 2
End If
End If


If count1 = 3 Then
s3 = Right(Text1.Text, 1)
If s3 = "+" Or s3 = "-" Then
s3_3 = 1
ElseIf s3 = "*" Or s3 = "/" Then
s3_3 = 2
End If

Select Case (s1_1 - s2_2)
Case -1
Select Case (s2)
Case "*"
b = b * c
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
b = b / c
End Select
s2 = s3
s2_2 = s3_3
temp2 = temp3

Case 1
Select Case (s1)
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
s1 = s2
s2 = s3
s1_1 = s2_2
s2_2 = s3_3
temp1 = temp2
temp2 = temp3
b = c

Case 0
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
b = c
s1 = s2
s2 = s3
s1_1 = s2_2
s2_2 = s3_3

End Select
End If


If count1 = 3 Then
count1 = 2
End If
count2 = 0
End Sub

Private Sub Command3_Click()

c = Val(temp)
Text1.Text = Text1.Text + "="
temp = Text1.Text
If count1 = 2 Then
Select Case (s1_1 - s2_2)
Case -1
Select Case (s2)
Case "*"
b = b * c
Case "/"
If c = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
b = b / c
End Select
s2 = s3
s2_2 = s3_3
temp2 = temp3

Case 1
Select Case (s1)
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
s1 = s2
s2 = s3
s1_1 = s2_2
s2_2 = s3_3
temp1 = temp2
temp2 = temp3
b = c

Case 0
Select Case (s1)
Case "+"
a = a + b
Case "-"
a = a - b
Case "*"
a = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
a = a / b
End Select
b = c
s1 = s2
s2 = s3
s1_1 = s2_2
s2_2 = s3_3

End Select
End If
If count1 = 1 Then
b = c
End If
Select Case (s1)

Case "+"
Text1.Text = a + b
Case "-"
Text1.Text = a - b
Case "*"
Text1.Text = a * b
Case "/"
If b = 0 Then
MsgBox "错误!!除数不能为0!!请重新输入除数!!", , "错误警告"
Exit Sub
End If
Text1.Text = a / b

End Select
Text1.Text = temp + Text1.Text
count_equ = 1
End Sub

Private Sub Command4_Click()
If Text1.Text <> "" Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - Len(temp))
End If
End Sub

Private Sub Command5_Click()
Text1.Text = ""
temp = 0
a = 0: b = 0: c = 0
s1_1 = 0: s2_2 = 0: s3_3 = 0
count1 = 0: count2 = 0: count_doc = 0
count_equ = 0
End Sub

Private Sub Command6_Click()
End
End Sub

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



Private Sub Command8_Click(Index As Integer)
Exit Sub
Select Case (Index)
Case 0
Text1.Text = Text1.Text + "("
n = 6
Case 1
Text1.Text = Text1.Text + ")"
n = 7
End Select
End Sub

Private Sub Command9_Click()
If temp <> "" Then
temp = Left(temp, Len(temp) - 1)
End If
If Text1.Text <> "" And Right(Text1.Text, 1) <> "+" And Right(Text1.Text, 1) <> "-" And Right(Text1.Text, 1) <> "*" And Right(Text1.Text, 1) <> "/" Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub

⌨️ 快捷键说明

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