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

📄 mdlmain.bas

📁 基于化工行业造气岗位的自动化监控系统
💻 BAS
📖 第 1 页 / 共 4 页
字号:
    Dim RecordNums As Long
    Dim i As Long
    On Error GoTo errhandle
    If FileName <> "" Then
        FileHandle = FreeFile
        Open FileName For Random As #FileHandle Len = Len(MotherBoard(0))
        RecordNums = LOF(FileHandle) / Len(MotherBoard(0))
        ReDim Preserve MotherBoard(0 To RecordNums - 1)
        For i = 1 To RecordNums Step 1
            Get #FileHandle, i, MotherBoard(i - 1)
'            Debug.Print MotherBoard(i - 1).Name & "+" & MotherBoard(i - 1).Address & "+" & MotherBoard(i - 1).Slot(0).Name & "+" & MotherBoard(i - 1).Slot(1).Name
        Next i
        Close #FileHandle
        If RecordNums = 0 Then
            OpenMotherBoardMap = 0
        Else
            OpenMotherBoardMap = 1
        End If
    Else
        OpenMotherBoardMap = 0
    End If
    Exit Function
errhandle:
    Err.Clear
    OpenMotherBoardMap = 0
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'函数名称:  calc
'参数:      expressions 类型(string),可包含运算符:+-*/,sqr,sin,cos,tan,atn,log,exp,()
'返回值:    计算值 类型(string)
'功能:      计算表达式的值
'作者:      李志有
'编写日期:  2004-7-22
'修改日期:  2004-7-28
'修改人:    李志有
'调用例子:calc("tan9.232-sqr(323)*(log534-34)/(exp3+sqr(43))")
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function Calc(expressions As String) As String
 Dim i As Long, j As Long, k As Long
 Dim D As Double
 Dim Tempstr As String
 On Error GoTo errhandle:
'  Debug.Print expressions
 
 i = InStr(1, expressions, "+-")
 If i <> 0 Then
      Tempstr = Replace$(expressions, "+-", "-")
      expressions = Tempstr
 End If
 i = InStr(1, expressions, "-+")
 If i <> 0 Then
      Tempstr = Replace$(expressions, "-+", "-")
      expressions = Tempstr
 End If
 i = InStr(1, expressions, "--")
 If i <> 0 Then
      Tempstr = Replace$(expressions, "--", "+")
      expressions = Tempstr
 End If
 i = InStr(1, expressions, "++")
 If i <> 0 Then
      Tempstr = Replace$(expressions, "++", "+")
      expressions = Tempstr
 End If
 i = InStr(1, expressions, "sqr")

 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Sqr(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
 i = InStr(1, expressions, "sin")
 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Sin(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
 i = InStr(1, expressions, "cos")
 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Cos(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
 i = InStr(1, expressions, "tan")
 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Tan(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
  i = InStr(1, expressions, "log")
 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Log(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
  i = InStr(1, expressions, "exp")
 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Exp(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
  i = InStr(1, expressions, "atn")
 If i <> 0 Then
   k = 1
   j = i + 4
   For j = i + 4 To Len(expressions)
    If Mid$(expressions, j, 1) = ")" Then
      k = k - 1
      If k = 0 Then
         Exit For
      End If
    End If
    If Mid$(expressions, j, 1) = "(" Then
      k = k + 1
    End If
   Next
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, CStr(Atn(Val(Calc(Mid$(Tempstr, 5, j - i - 4))))), 1, 1))
   Exit Function
 End If
 j = InStr(1, expressions, ")")
 If j <> 0 Then
   i = j - 1
   Do While (i > 0)
     If (Mid$(expressions, i, 1) = "(") Then
       Exit Do
     End If
     i = i - 1
   Loop
   Tempstr = Mid$(expressions, i, j - i + 1)
   Calc = Calc(Replace$(expressions, Tempstr, Calc(Mid$(Tempstr, 2, j - i - 1)), 1, 1))
   Exit Function
 End If
 i = InStr(1, expressions, "*")
 j = InStr(1, expressions, "/")
 If i <> 0 Or j <> 0 Then
   If j * i = 0 Then
    If i = 0 Then
     i = j
    End If
   Else
     If i > j Then
       i = j
     End If
   End If
 Else
   GoTo out
 End If
  k = i - 1
 Do While (k > 0)
    Tempstr = Mid$(expressions, k, 1)
    If Tempstr = "+" Or Tempstr = "-" Then
      If k > 1 Then
        If Mid$(expressions, k - 1, 1) = "E" Then
          k = k - 2
          Tempstr = Mid$(expressions, k, 1)
        End If
      End If
    End If
    If Not (Tempstr = "." Or IsNumeric(Tempstr)) Then
      Exit Do
    End If
    k = k - 1
  Loop
  k = k + 1
  D = Val(Mid$(expressions, k, i - k))
  j = i + 1
  If Mid$(expressions, j, 1) = "-" Or Mid$(expressions, j, 1) = "+" Then
   j = j + 1
  End If
  Do While (j < Len(expressions) + 1)
    Tempstr = Mid$(expressions, j, 1)
    If Tempstr = "E" Then
          j = j + 2
          Tempstr = Mid$(expressions, j, 1)
    End If
    If Not (Tempstr = "." Or IsNumeric(Tempstr)) Then
      Exit Do
    End If
    j = j + 1
  Loop
  j = j - 1
  Tempstr = Mid$(expressions, k, j - k + 1)
  If Mid$(expressions, i, 1) = "*" Then
    Calc = Calc(Replace$(expressions, Tempstr, CStr(D * Val(Mid$(expressions, i + 1, j - i))), 1, 1))
  Else
    Calc = Calc(Replace$(expressions, Tempstr, CStr(D / Val(Mid$(expressions, i + 1, j - i))), 1, 1))
  End If
  Exit Function
out:
 i = 2
 j = 2
restart:
 i = InStr(i, expressions, "+")
 j = InStr(j, expressions, "-")
 If i <> 0 Or j <> 0 Then
    If j * i = 0 Then
      If i = 0 Then
       i = j
      End If
    Else
        If i > j Then
          i = j
        End If
    End If
 Else
   Calc = expressions
   Exit Function
 End If
 k = i - 1
 If Mid$(expressions, k, 1) = "E" Then
   i = i + 2
   j = i
   GoTo restart
 End If
  Do While (k > 0)
    Tempstr = Mid$(expressions, k, 1)
    If Tempstr = "+" Or Tempstr = "-" Then
      If k > 1 Then
        If Mid$(expressions, k - 1, 1) = "E" Then
          k = k - 2
          Tempstr = Mid$(expressions, k, 1)
        Else
          Exit Do
        End If
      End If
    End If
    
    If Not (Tempstr = "." Or IsNumeric(Tempstr)) Then
      Exit Do
    End If
    k = k - 1
  Loop
  k = k + 1
  D = Val(Mid$(expressions, k, i - k))
  j = i + 1
  Do While (j < Len(expressions) + 1)
    Tempstr = Mid$(expressions, j, 1)
    If Tempstr = "E" Then
          j = j + 2
          Tempstr = Mid$(expressions, j, 1)
    End If
    If Not (Tempstr = "." Or IsNumeric(Tempstr)) Then
      Exit Do
    End If
    j = j + 1
  Loop
  j = j - 1
  Tempstr = Mid$(expressions, k, j - k + 1)
  If Mid$(expressions, i, 1) = "+" Then
   If Mid$(expressions, 1, 1) = "-" Then
    Calc = Calc(Replace$(expressions, Tempstr, CStr(D - Val(Mid$(expressions, i + 1, j - i))), 1, 1))
   Else
    Calc = Calc(Replace$(expressions, Tempstr, CStr(D + Val(Mid$(expressions, i + 1, j - i))), 1, 1))
   End If
  Else
    If Mid$(expressions, 1, 1) = "-" Then
      Calc = Calc(Replace$(expressions, Tempstr, CStr(D + Val(Mid$(expressions, i + 1, j - i))), 1, 1))
    Else
       Calc = Calc(Replace$(expressions, Tempstr, CStr(D - Val(Mid$(expressions, i + 1, j - i))), 1, 1))
    End If
  End If
  Exit Function
errhandle:
  Calc = expressions
  Err.Clear
End Function

⌨️ 快捷键说明

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