📄 ana.bas
字号:
Attribute VB_Name = "ana"
Public Type 变量表
名称 As String
数据 As String
End Type
Public bb() As 变量表
Public dx As New SimpleDX8II
Public dx2 As New SimpleDX8IIFJ
Public dd As New D2D
Public dd2 As New D2DFJ
Public di As New DInput
Public dm As New DMusic
Public ds As New DSound
Public dsh As New SDShow
Public 窗口化 As Boolean
Public 当前窗口 As Long
Public 当前窗口2 As Long
Public 窗口单位 As Object
Public 宽2 As Integer
Public 高2 As Integer
Public 路径 As String
Public Const PI = 3.1415926
Public keys(255) As Long
Public Function 公式计算(GS As String) As String
Dim i, n As Integer
Dim TempGs, Temp As String
Dim Vl() As String '操作数
Dim Vls As Integer '操作数的数目
Dim Si As Integer '上一操作符的位置
Dim Ads, Sus, Mus, Bys, Lks, Rks As Integer '操作符的数目
Dim Adp(), Mup(), Byp(), Lkp(), Rkp() As Integer '操作符的位置
Dim Adn(), Mun(), Byn() As Integer '操作符的排列次序
Dim Sig() As Integer '每一个操作符的位置
On Error GoTo Err
Do While True
ReDim Adp(Len(GS)), Mup(Len(GS)), Byp(Len(GS)) _
, Lkp(Len(GS)), Rkp(Len(GS)) As Integer
ReDim Adn(Len(GS)), Mun(Len(GS)), Byn(Len(GS)) _
, Lkn(Len(GS)), Rkn(Len(GS)), Sig(Len(GS)) As Integer
ReDim Vl(Len(GS))
If Len(GS) = 0 Then GoTo Err
If Mid(GS, Len(GS), 1) <> "#" Then
TempGs = GS
For i = 1 To Len(GS) '将减化加
If Mid(GS, i, 1) = "-" And i <> 1 Then
If Mid(GS, i - 1, 1) <> "+" And Mid(GS, i - 1, 1) <> "-" _
And Mid(GS, i - 1, 1) <> "*" And Mid(GS, i - 1, 1) <> "/" Then
TempGs = Mid(TempGs, 1, i - 1 + n) + "+" + Mid(GS, i)
n = n + 1
End If
End If
Next i
GS = TempGs
n = 0
For i = 1 To Len(GS) '处理负负得正
If Mid(GS, i, 1) = "-" Then
If Mid(GS, i + 1, 1) = "-" Then
TempGs = Mid(TempGs, 1, i - 1 - n) + Mid(GS, i + 2)
n = n + 2
End If
End If
Next i
GS = TempGs
GS = GS + "#"
End If
Vls = 1
Ads = 0: Sus = 0: Mus = 0: Bys = 0: Lks = 0: Rks = 0
For i = 1 To Len(GS)
Select Case Mid(GS, i, 1)
Case "+"
Ads = Ads + 1
Adp(Ads) = i
Adn(Ads) = Vls
Case "*"
Mus = Mus + 1
Mup(Mus) = i
Mun(Mus) = Vls
Case "/"
Bys = Bys + 1
Byp(Bys) = i
Byn(Bys) = Vls
Case "("
Lks = Lks + 1
Lkp(Lks) = i
Case ")"
Rks = Rks + 1
Rkp(Rks) = i
End Select
If Mid(GS, i, 1) = "+" Or Mid(GS, i, 1) = "*" Or _
Mid(GS, i, 1) = "/" Or Mid(GS, i, 1) = "#" Then
If Si + 1 = i And Mid(GS, i + 1, 1) <> "#" _
Then '操作符非法连续或以操作符开头
GoTo Err
Else
Si = i
End If
If Not IsNumeric(Vl(Vls)) And Mid(GS, i + 1, 1) <> "#" _
Then '操作数不是数字
GoTo Err
End If
Sig(Vls) = i
Vls = Vls + 1
Else
If Mid(GS, i, 1) <> "(" And Mid(GS, i, 1) <> ")" Then
Vl(Vls) = Vl(Vls) + Mid(GS, i, 1) '制作操作数
Else
If i <> 1 Then
If ((Mid(GS, i - 1, 1) = "(" And Mid(GS, i, 1) = ")") Or _
(Mid(GS, i - 1, 1) = ")" And Mid(GS, i, 1) = "(")) _
Then '判定括号前后符号的合法性
GoTo Err
End If
End If
End If
End If
Next i
If Lks <> Rks Then
GoTo Err '左右括号数是否匹配
End If
For i = 1 To Lks
If Lkp(i) > Rkp(i) Then GoTo Err '左右括号出现顺序错误
Next i
If Lks <> 0 Then '括号处理
Do While True
For i = Lks To 1 Step -1
For n = Rks To 1 Step -1
Temp = 公式计算(Mid(GS, Lkp(i) + 1, Rkp(n) - Lkp(i) - 1))
If Temp <> "公式有错误" Then
GS = Mid(GS, 1, Lkp(i) - 1) + Temp + Mid(GS, Rkp(n) + 1)
Exit Do
End If
Next n
Next i
If Temp = "公式有错误" Then GoTo Err
'括号中有错误退出
Loop
Else
If Mus <> 0 Then '乘法处理
GS = Mid(GS, 1, Sig(Mun(1) - 1)) + Trim(Str(Val(Vl(Mun(1))) _
* Val(Vl(Mun(1) + 1)))) + Mid(GS, Val(Mup(1)) + Len(Vl(Mun(1) _
+ 1)) + 1)
Else
If Bys <> 0 Then '除法处理
GS = Mid(GS, 1, Sig(Byn(1) - 1)) + Trim(Str(Val(Vl(Byn(1))) _
/ Val(Vl(Byn(1) + 1)))) + Mid(GS, Val(Byp(1)) + Len(Vl(Byn(1) _
+ 1)) + 1)
Else
If Ads <> 0 Then '加法处理
GS = Trim(Str(Val(Vl(1)) + Val(Vl(2)))) + Mid(GS, Val(Adp(1)) _
+ Len(Vl(2)) + 1)
Else
公式计算 = Mid(GS, 1, Len(GS) - 1)
Exit Function
End If
End If
End If
End If
Loop
Err:
公式计算 = "公式有错误"
End Function
Public Function 变量翻译(变量表() As 变量表, GS As String) As String
Dim Temp() As String
Dim temp2(13) As String
Temp() = Split(GS, "+")
For i = 0 To UBound(Temp())
temp2(0) = temp2(0) & Temp(i) & " + "
Next
Temp() = Split(temp2(0), "-")
For i = 0 To UBound(Temp())
temp2(1) = temp2(1) & Temp(i) & " - "
Next
Temp() = Split(temp2(1), "(")
For i = 0 To UBound(Temp())
temp2(2) = temp2(2) & Temp(i) & " ( "
Next
Temp() = Split(temp2(2), ")")
For i = 0 To UBound(Temp())
temp2(3) = temp2(3) & Temp(i) & " ) "
Next
Temp() = Split(temp2(3), "*")
For i = 0 To UBound(Temp())
temp2(4) = temp2(4) & Temp(i) & " * "
Next
Temp() = Split(temp2(4), "/")
For i = 0 To UBound(Temp())
temp2(5) = temp2(5) & Temp(i) & " / "
Next
Temp() = Split(temp2(5), " ")
For i = 0 To UBound(Temp())
For j = 0 To UBound(变量表())
If 变量表(j).名称 = Temp(i) Then
Temp(i) = 变量表(j).数据
End If
Next
Next
For i = 0 To UBound(Temp()) - 12
temp2(6) = temp2(6) & " " & Temp(i)
Next
Temp() = Split(temp2(6), "+ -")
For i = 0 To UBound(Temp())
temp2(7) = temp2(7) & Temp(i) & " - "
Next
Temp() = Split(temp2(7), "* -")
For i = 0 To UBound(Temp())
temp2(8) = temp2(8) & Temp(i) & " * (1-2) * "
Next
Temp() = Split(temp2(8), "/ -")
For i = 0 To UBound(Temp())
temp2(9) = temp2(9) & Temp(i) & " * (1-2) / "
Next
Temp() = Split(temp2(9), "- -")
For i = 0 To UBound(Temp())
temp2(10) = temp2(10) & Temp(i) & " + "
Next
Temp() = Split(temp2(10), "( -")
For i = 0 To UBound(Temp())
temp2(11) = temp2(11) & Temp(i) & " ( 0 - "
Next
Temp() = Split(temp2(11), "( +")
For i = 0 To UBound(Temp())
temp2(12) = temp2(12) & Temp(i) & " ( "
Next
Temp() = Split(temp2(12), " ")
For i = 0 To UBound(Temp())
For j = 0 To UBound(变量表())
If 变量表(j).名称 = Temp(i) Then
Temp(i) = 变量表(j).数据
End If
Next
Next
For i = 0 To UBound(Temp()) - 18
temp2(13) = temp2(13) & " " & Temp(i)
Next
Temp() = Split(temp2(13), " ")
temp2(13) = ""
For i = 0 To UBound(Temp())
temp2(13) = temp2(13) & Temp(i)
Next
变量翻译 = 公式计算(temp2(13))
End Function
Public Function 比较脚本分析(GS1 As String, GS2 As String, 变量表() As 变量表) As Integer
比较脚本分析 = Val(变量翻译(变量表(), GS1)) - Val(变量翻译(变量表(), GS2))
End Function
Function 翻译变量2(变量名, bb() As 变量表) As String
For i = 0 To UBound(bb)
If bb(i).名称 = 变量名 Then
翻译变量2 = bb(i).数据
Exit Function
End If
Next
翻译变量2 = 变量名
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -