一个变量转换成运算符的问题????????

yanrwang 2003-10-15 04:35:35
例如:
dim a,b,c as integer
dim br as boolean
dim symbol as string

if br = true then
symbol = "+"
else
symbol = "-"
end if

c=a & symbol & b

无法求解c的值(得出的结果为"a+b",变成字符串了)
我的问题就是例子中的symbol如何才能真正转化成有意义的运算符???????
...全文
28 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanrwang 2003-10-16
  • 打赏
  • 举报
回复
hi,cuizm(射天狼) 你好!
首先非常感谢你的支持和帮助,我试了你给出的例子运行无误,但是我用变量()替换你例子中的数字却无法运行,不知是何原因???
射天狼 2003-10-16
  • 打赏
  • 举报
回复
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

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

Private Sub Command1_Click()
ExecuteLine "dim i as long ,j as long "
ExecuteLine "i = 1:j=3"
ExecuteLine "msgbox i + j"
ExecuteLine "msgbox (1+2)*3/4"
ExecuteLine "dim a as string"
ExecuteLine "a = ""dd"""
ExecuteLine "msgbox a"
End Sub
kmzs 2003-10-15
  • 打赏
  • 举报
回复
dim a,b,c as integer
dim br as boolean
dim symbol as string

if br = true then
c=a+b
else
c=a-b
end if
射天狼 2003-10-15
  • 打赏
  • 举报
回复
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

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

Private Sub Command1_Click()
ExecuteLine "msgbox (1+2)*3/4"
ExecuteLine "dim a as string"
ExecuteLine "a = ""dd"""
ExecuteLine "msgbox a"
End Sub
strongfisher 2003-10-15
  • 打赏
  • 举报
回复
f br = true then
c=a+b
else
c=a-b
end if

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧