利用API 实现字符串表达式的计算

发表于:2007-07-01来源:作者:点击数: 标签:
下面实现字符串表达式计算代码由笔者收藏的本论坛代码改编,记不清是哪位网友提供的了,非常感谢。 Option Explicit Private Declare Function EbExecuteLine Lib " vb a6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As

下面实现字符串表达式计算代码由笔者收藏的本论坛代码改编,记不清是哪位网友提供的了,非常感谢。

Option Explicit
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long

Private Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
    ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function


Sub calc(ByVal x As String)
Dim result
ExecuteLine "dim x as double"
ExecuteLine "x= " & x
ExecuteLine "clipboard.settext x"
result = Clipboard.GetText
MsgBox x & "=" & result
Set result = Nothing
End Sub

Private Sub Command1_Click()
calc Text1
End Sub

Private Sub Form_Load()
Text1.Text = "1+2*3-4/5"
End Sub


原文转自:http://www.ltesting.net