VB如何处理数学表达式
2个回答
展开全部
Private
Declare
Function
EbExecuteLine
Lib
"vba6.dll"
_
(ByVal
StringToExec
As
Long,
ByVal
Any1
As
Long,
_
ByVal
Any2
As
Long,
ByVal
CheckOnly
As
Long)
As
Long
Dim
Variable
As
Variant
Function
ExecuteCode(Code
As
String,
Optional
CheckOnly
As
Boolean)
As
Boolean
ExecuteCode
=
EbExecuteLine(StrPtr(Code),
0&,
0&,
CheckOnly)
=
0
End
Function
Private
Sub
Command1_Click()
Dim
Code
As
String
Code
=
Replace(Text1.Text,
vbCrLf,
":")
Call
ExecuteCode(Code)
End
Sub
Private
Sub
Form_Load()
Text1.Text
=
"a=(1+2)*3-52+cos(1)"
+
vbCrLf
+
"
Variable=a"
+
vbCrLf
+
"
msgbox
a"
Label1.Caption
=
"请在文本框中输一段代码,看看效果"
End
Sub
把数组Oprt()中的数据相应转换为你设置的操作数或符号后加入text1字符串.....应该没什么问题了,vb6中测试通过
Declare
Function
EbExecuteLine
Lib
"vba6.dll"
_
(ByVal
StringToExec
As
Long,
ByVal
Any1
As
Long,
_
ByVal
Any2
As
Long,
ByVal
CheckOnly
As
Long)
As
Long
Dim
Variable
As
Variant
Function
ExecuteCode(Code
As
String,
Optional
CheckOnly
As
Boolean)
As
Boolean
ExecuteCode
=
EbExecuteLine(StrPtr(Code),
0&,
0&,
CheckOnly)
=
0
End
Function
Private
Sub
Command1_Click()
Dim
Code
As
String
Code
=
Replace(Text1.Text,
vbCrLf,
":")
Call
ExecuteCode(Code)
End
Sub
Private
Sub
Form_Load()
Text1.Text
=
"a=(1+2)*3-52+cos(1)"
+
vbCrLf
+
"
Variable=a"
+
vbCrLf
+
"
msgbox
a"
Label1.Caption
=
"请在文本框中输一段代码,看看效果"
End
Sub
把数组Oprt()中的数据相应转换为你设置的操作数或符号后加入text1字符串.....应该没什么问题了,vb6中测试通过
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询