For i = 1 To Len(str)
If Mid(str, i, 1) <> "(" And Mid(str, i, 1) <> ")" And Mid(str, i, 1) <> "0" And Mid(str, i, 1) <> "." And Mid(str, i, 1) <> "1" And Mid(str, i, 1) <> "2" And Mid(str, i, 1) <> "3" And Mid(str, i, 1) <> "4" And Mid(str, i, 1) <> "5" And Mid(str, i, 1) <> "6" And Mid(str, i, 1) <> "7" And Mid(str, i, 1) <> "8" And Mid(str, i, 1) <> "9" And Mid(str, i, 1) <> "" And Mid(str, i, 1) <> "+" And Mid(str, i, 1) <> "-" And Mid(str, i, 1) <> "/" And Mid(str, i, 1) <> "*" Then
If Mid(str, i + 3, 1) <> "(" Then
For n = i + 3 To Len(str)
If Val(Mid(str, n, 1)) = 0 And Mid(str, n, 1) <> "0" And Mid(str, n, 1) <> "." Then
computer = computer + Mid(str, i, 3) + "(" + Mid(str, i + 3, n - i - 3) + ")"
i = n - 1
Exit For
End If
If n = Len(str) Then
computer = computer + Mid(str, i, 3) + "(" + Right(str, Len(str) - i - 2) + ")"
i = Len(str)
End If
Next n
Else
computer = computer + Mid(str, i, 3)
i = i + 2
End If
Else
computer = computer + Mid(str, i, 1)
End If
Next i
str = computer
computer = ""
'给省了乘号的加乘号
For i = 1 To Len(str)
computer = computer + Mid(str, i, 1)
If i < Len(str) Then
If Mid(str, i, 1) = ")" Then ')后面省了*号
If Mid(str, i + 1, 1) <> ")" And Mid(str, i + 1, 1) <> "+" And Mid(str, i + 1, 1) <> "-" And Mid(str, i + 1, 1) <> "*" And Mid(str, i + 1, 1) <> "/" Then
computer = computer + "*"
End If
End If
End If
Next i
str = computer
computer = ""
For i = 1 To Len(str) '(前面省了*号
If Mid(str, i, 1) = "(" And i <> 1 Then
If Mid(str, i - 1, 1) = "0" Or Mid(str, i - 1, 1) = ")" Or Val(Mid(str, i - 1, 1)) > 0 Then
computer = computer + "*"
End If
End If
computer = computer + Mid(str, i, 1)
Next i
'判断常见的函数如:sin cos tan....等等哦
Dim k As Long
Dim q As String
Dim h As String
Dim temp
Dim tem As String
Dim x
Dim t
j: k = InStr(computer, "sin(") '查找字符串“sin(”
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Sin(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo j
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm: k = InStr(computer, "cos(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Cos(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm1: k = InStr(computer, "tan(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Tan(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm1
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm2: k = InStr(computer, "atn(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Atn(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm2
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm3: k = InStr(computer, "sqr(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Sqr(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm3
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm4: k = InStr(computer, "abs(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = Abs(computer(Mid(computer, k + 4, t)))
computer = q + tem + h
GoTo jm4
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
If Mid(str, i, 1) <> "(" And Mid(str, i, 1) <> ")" And Mid(str, i, 1) <> "0" And Mid(str, i, 1) <> "." And Mid(str, i, 1) <> "1" And Mid(str, i, 1) <> "2" And Mid(str, i, 1) <> "3" And Mid(str, i, 1) <> "4" And Mid(str, i, 1) <> "5" And Mid(str, i, 1) <> "6" And Mid(str, i, 1) <> "7" And Mid(str, i, 1) <> "8" And Mid(str, i, 1) <> "9" And Mid(str, i, 1) <> "" And Mid(str, i, 1) <> "+" And Mid(str, i, 1) <> "-" And Mid(str, i, 1) <> "/" And Mid(str, i, 1) <> "*" Then
If Mid(str, i + 3, 1) <> "(" Then
For n = i + 3 To Len(str)
If Val(Mid(str, n, 1)) = 0 And Mid(str, n, 1) <> "0" And Mid(str, n, 1) <> "." Then
computer = computer + Mid(str, i, 3) + "(" + Mid(str, i + 3, n - i - 3) + ")"
i = n - 1
Exit For
End If
If n = Len(str) Then
computer = computer + Mid(str, i, 3) + "(" + Right(str, Len(str) - i - 2) + ")"
i = Len(str)
End If
Next n
Else
computer = computer + Mid(str, i, 3)
i = i + 2
End If
Else
computer = computer + Mid(str, i, 1)
End If
Next i
str = computer
computer = ""
'给省了乘号的加乘号
For i = 1 To Len(str)
computer = computer + Mid(str, i, 1)
If i < Len(str) Then
If Mid(str, i, 1) = ")" Then ')后面省了*号
If Mid(str, i + 1, 1) <> ")" And Mid(str, i + 1, 1) <> "+" And Mid(str, i + 1, 1) <> "-" And Mid(str, i + 1, 1) <> "*" And Mid(str, i + 1, 1) <> "/" Then
computer = computer + "*"
End If
End If
End If
Next i
str = computer
computer = ""
For i = 1 To Len(str) '(前面省了*号
If Mid(str, i, 1) = "(" And i <> 1 Then
If Mid(str, i - 1, 1) = "0" Or Mid(str, i - 1, 1) = ")" Or Val(Mid(str, i - 1, 1)) > 0 Then
computer = computer + "*"
End If
End If
computer = computer + Mid(str, i, 1)
Next i
'判断常见的函数如:sin cos tan....等等哦
Dim k As Long
Dim q As String
Dim h As String
Dim temp
Dim tem As String
Dim x
Dim t
j: k = InStr(computer, "sin(") '查找字符串“sin(”
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Sin(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo j
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm: k = InStr(computer, "cos(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Cos(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm1: k = InStr(computer, "tan(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Tan(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm1
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm2: k = InStr(computer, "atn(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Atn(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm2
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm3: k = InStr(computer, "sqr(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = CCur(Sqr(computer(Mid(computer, k + 4, t))))
computer = q + tem + h
GoTo jm3
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
jm4: k = InStr(computer, "abs(")
If k <> 0 Then
t = 0
x = 0
q = Left(computer, k - 1)
For i = k + 4 To Len(computer)
temp = Mid(computer, i, 1)
If (temp = "(") Then x = x + 1
If (temp = ")") Then
If (x = 0) Then
h = Mid(computer, i + 1, Len(computer) - i)
tem = Abs(computer(Mid(computer, k + 4, t)))
computer = q + tem + h
GoTo jm4
Else: x = x - 1
End If
End If
t = t + 1
Next i
End If
--------------------------------------------------------------
程序,犹如人生。