请教各位一个vb api在vb.net中使用
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
一个在VB计算用字符串写的表达式的api,例如
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()
text1.text= "1+1+1*100"
calc Text1
End Sub
点击command1,msgbox显示:1+1+1*100=102
请教各位如何在vb.net中声明此api???
[解决办法]
不要试图使用这个api,事实上这个api在VB6里面就不能工作。它依赖IDE才能调用,而在编译的exe里面是无效的。
表达式计算参考:http://topic.csdn.net/u/20110430/02/a3a306f8-2e21-4271-b3c5-35e2018933be.html
[解决办法]
Microsoft Script Control
推荐使用
[解决办法]
实在不行自己写个好了,不难吧这逻辑
[解决办法]
Dim sc = CreateObject("ScriptControl")
sc.language = "VBScript"
Dim _s$ = "1+1+1*100"
Dim Result$ = sc.Eval(_s)
MsgBox(_s & "=" & Result)
[解决办法]
你现在不就是一个不定公式么?
你根据人家输入的符号去写公式就好了啊
比如说给人家选项 A 除以/乘以 B =?
那你就翻译成vb代码嘛
不知道是不是这个意思,看不懂纠结什么