-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.frm
192 lines (188 loc) · 5.52 KB
/
Form1.frm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
VERSION 5.00
Begin VB.Form Form1
Caption = "表达式计算"
ClientHeight = 3195
ClientLeft = 5700
ClientTop = 2265
ClientWidth = 5475
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 5475
Begin VB.CommandButton Command2
Caption = "快算"
Height = 300
Left = 4680
TabIndex = 2
Top = 120
Width = 735
End
Begin VB.TextBox Text3
Height = 2055
Left = 3600
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 8
Top = 1080
Width = 975
End
Begin VB.TextBox Text2
Height = 2415
Left = 2520
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 4
Top = 720
Width = 975
End
Begin VB.TextBox Text1
Height = 2415
Left = 600
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 720
Width = 1215
End
Begin VB.TextBox SourceText
Height = 270
Left = 120
TabIndex = 0
Top = 120
Width = 3615
End
Begin VB.CommandButton Command1
Caption = "Calc"
Height = 300
Left = 3840
TabIndex = 1
Top = 120
Width = 735
End
Begin VB.Label Label3
Caption = "结果为"
Height = 255
Left = 3720
TabIndex = 7
Top = 720
Width = 615
End
Begin VB.Label Label2
Caption = "数字栈"
Height = 255
Left = 1920
TabIndex = 6
Top = 720
Width = 615
End
Begin VB.Label Label1
Caption = "操作符"
Height = 255
Left = 0
TabIndex = 5
Top = 720
Width = 615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'说明:
'本代码基于GNU开放源代码协议
'
'并补充如下限制,若限制内容与通行GNU协议
'违背,以本文本为主
'
'Designed By Sun Rui·孙瑞
'E-mail:[email protected]
'武汉理工大学电子信息工程专业
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '声明
Private Sub Command1_Click()
Dim sTxt As String
Dim strNumFix As String
Dim curChar As String
Dim i As Long
Dim signCount As Long
Dim ops1 As String, ops2 As String, opC As String
'先清空:
Text3.Text = ""
'初始化堆栈
opNum.Clear
opChar.Clear
Call UpdateShow
'堆栈初始化结束
sTxt = SourceText.Text
For i = 1 To Len(sTxt)
curChar = Mid(sTxt, i, 1)
If IsSymbol(curChar) = True Then
'看看数字预备区有没有
If strNumFix <> "" Then
opNum.Push strNumFix
Call UpdateShow
strNumFix = ""
End If
redo:
If IsHigh(curChar, opChar.Peek) = 1 Then 'if new come char is higher then push it to stack
opChar.Push curChar '如果等级高的控制符,则进入
signCount = signCount + 1
Call UpdateShow
ElseIf IsHigh(curChar, opChar.Peek) = 0 Then
'Debug.Print "结果是:" & opNum.Pop
'Exit Sub
If curChar = "#" And opChar.Peek = "#" Then
opChar.Pop
Call UpdateShow
Text3.Text = "输出结果是:" & opNum.Pop
Call UpdateShow
Exit Sub
End If
ElseIf IsHigh(curChar, opChar.Peek) = -1 Then 'if low then ready to calculate
'判断是不是第一个符号
If signCount = 1 Then '这个符号是刚刚输入#后的那个,无论如何入栈
opChar.Push curChar
signCount = signCount + 1
GoTo nextone
End If
ops2 = opNum.Pop
Call UpdateShow
ops1 = opNum.Pop
Call UpdateShow
opC = opChar.Pop
Call UpdateShow
opNum.Push CStr(Calc(ops1, ops2, opC))
Call UpdateShow
If curChar = ")" And opChar.Peek = "(" Then
opChar.Pop '如果操作数是),就把(弹出来
Call UpdateShow
GoTo moveon
End If
GoTo redo
moveon:
End If
Else '非符号
strNumFix = strNumFix & curChar
End If
nextone:
Next i
End Sub
Private Sub Command2_Click()
Text3.Text = CalcString(SourceText.Text)
End Sub
Private Sub Form_Load()
Me.Show
opNum.Clear
opChar.Clear
End Sub
Sub Delay(ByVal msec As Long) '函数:msec为毫秒数
DoEvents
Sleep msec
End Sub
Sub UpdateShow()
DoEvents
Text1.Text = opChar.ViewStack
DoEvents
Text2.Text = opNum.ViewStack
DoEvents
Call Delay(500)
End Sub