文本框如何进行计算

sspynnwg 2003-10-15 11:09:33
我在文本框中输入要计算的式子(如1+5+2+78或12>56),在另一个文本框中得出答案。我曾在VFP中用宏命令完成过,不知在VB中如何完成,请解答!多谢!
...全文
150 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hcj2002 2003-10-21
  • 打赏
  • 举报
回复
受益匪浅
谢谢
AustinLei 2003-10-18
  • 打赏
  • 举报
回复
'先引用Microsoft Script Control 1.0
Private Sub Command1_Click()
Dim sc As New ScriptControl
Set sc = CreateObject("ScriptControl")
sc.Language = "vbscript"
Text2.Text = sc.Eval(Text1.Text)
End Sub
langzijo 2003-10-18
  • 打赏
  • 举报
回复
楼上的老大很厉害,每错
其实文本框中输入的东西都是一串字符,数字和运算符也被定为字符格式要用判断语句判断运算符
而且要用cstr语句和val将数字字符串转换为数字
do you understand?
zlpanzy 2003-10-16
  • 打赏
  • 举报
回复
你得用循环判断 字符
for i =1 to len(text1)
dim StrZf as string
StrZf =right(left(text1,i),1)
if StrZf <> "+" or StrZf <> ">" ... then
StrNumber = StrNumber + StrZf
else
StrOperator = StrZf
if strOperator = "+" then
text2 =cstr(val(text2) + val(StrNumber ))
elseif strOperator = ">" then
...
end if
StrNumber =""
end if

next

1,066

社区成员

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

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