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

📄 calc.bas

📁 VB6 Consol Window Demo
💻 BAS
📖 第 1 页 / 共 2 页
字号:
Attribute VB_Name = "ModCalc"
'CODE Manger By BcodeXRose
Option Explicit

'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:CalculateString
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Public Function CalculateString(ByVal Exppression As String, ByRef Good As Boolean, ByVal xxx As Double) As Double
    Dim isg As Boolean
    Dim ExppressionLength As Long
    Dim pp As Integer
    pp = 1
    ExppressionLength = Len(Exppression)
    CalculateString = E(Exppression, isg, pp, xxx)
    Good = isg
    If pp <= ExppressionLength Then Good = False
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:E
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function E(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp1 As Double
    Dim tmp2 As Double
    Dim isg As Boolean
    On Error GoTo Eerr
    tmp1 = t(Exppression, isg, position, xxx)
    If Match(Exppression, "+", position) Then
        position = position + 1
        tmp2 = E2(Exppression, isg, position, xxx)
        If Not (isg) Then
            Good = False
            Exit Function
        End If
        E = tmp1 + tmp2
    Else
        If Match(Exppression, "-", position) Then
            position = position + 1
            tmp2 = E2(Exppression, isg, position, xxx)
            If Not (isg) Then
                Good = False
                Exit Function
            End If
            E = tmp1 - tmp2
        Else
            E = tmp1
        End If
    End If
    Good = isg
    Exit Function
Eerr:
    Good = False
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:E2
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function E2(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp1 As Double
    Dim tmp2 As Double
    Dim isg As Boolean
    tmp1 = T2(Exppression, isg, position, xxx)
    If Match(Exppression, "+", position) Then
        position = position + 1
        tmp2 = E2(Exppression, isg, position, xxx)
        If Not (isg) Then
            Good = False
            Exit Function
        End If
        E2 = tmp1 + tmp2
    Else
        If Match(Exppression, "-", position) Then
            position = position + 1
            tmp2 = E2(Exppression, isg, position, xxx)
            If Not (isg) Then
                Good = False
                Exit Function
            End If
            E2 = tmp1 - tmp2
        Else
            E2 = tmp1
        End If
        Good = isg
    End If
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:t
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function t(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp1 As Double
    Dim tmp2 As Double
    Dim isg As Boolean
    tmp1 = f(Exppression, isg, position, xxx)
    If isg Then
        If Match(Exppression, "*", position) Then
            position = position + 1
            tmp2 = T2(Exppression, isg, position, xxx)
            If Not (isg) Then
                Good = False
                Exit Function
            End If
            t = tmp1 * tmp2
        Else
            If Match(Exppression, "/", position) Then
                position = position + 1
                tmp2 = T2(Exppression, isg, position, xxx)
                If Not (isg) Then
                    Good = False
                    Exit Function
                End If
                t = tmp1 / tmp2
            Else
                t = tmp1
            End If
        End If
    End If
    Good = isg
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:T2
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function T2(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp1 As Double
    Dim tmp2 As Double
    Dim isg As Boolean
    tmp1 = F2(Exppression, isg, position, xxx)
    If isg Then
        If Match(Exppression, "*", position) Then
            position = position + 1
            tmp2 = T2(Exppression, isg, position, xxx)
            If Not (isg) Then
                Good = isg
                Exit Function
            End If
            T2 = tmp1 * tmp2
        Else
            If Match(Exppression, "/", position) Then
                position = position + 1
                tmp2 = T2(Exppression, isg, position, xxx)
                If Not (isg) Then
                    Good = isg
                    Exit Function
                End If
                T2 = tmp1 / tmp2
            Else
                T2 = tmp1
            End If
        End If
    End If
    Good = isg
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:f
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function f(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp As Double
    Dim isg As Boolean
    tmp = OpDigital(Exppression, isg, position, xxx)
    If Not (isg) Then tmp = g(Exppression, isg, position, xxx)
    f = tmp
    Good = isg
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:F2
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function F2(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp As Double
    Dim isg As Boolean
    tmp = NonopDigital(Exppression, isg, position, xxx)
    If Not (isg) Then tmp = g(Exppression, isg, position, xxx)
    F2 = tmp
    Good = isg
End Function
    
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
'+----+----+--- 函数名称:g
'+----+----+--- 参数:ByVal 为pression As String型
'+----+----+--- 参数:ByRef 为d As Boolean型
'+----+----+--- 参数:ByRef 为ition As Integer型
'+----+----+--- 参数:ByVal 为 As Double型
'As Double'+----+----+--- 返回类型:As Double
'+----+----+----+----+----+----+----+----+----+----+----+----+----+
Private Function g(ByVal Exppression As String, ByRef Good As Boolean, ByRef position As Integer, ByVal xxx As Double) As Double
    Dim tmp1 As Double
    Dim tmp2 As Double
    Dim isg As Boolean
    Dim pi As Single
    
    Call PassBlank(Exppression, position)
    If Match(Exppression, "SIN", position) Then
        position = position + 3
        Call PassBlank(Exppression, position)

⌨️ 快捷键说明

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