It is currently Mon Feb 24, 2020 9:49 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject:
PostPosted: Mon Dec 11, 2006 1:16 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
You can also tap into the windows scripting host:
Code:
Procedure.d Evaluate(exp.s)
  If CreateFile(0,"tmp.vbs")
    WriteStringN(0, "wscript.stdout.writeline "+exp) : CloseFile(0)
    prg=RunProgram("wscript"," tmp.vbs",GetCurrentDirectory(),#PB_Program_Open|#PB_Program_Read)
    If prg
      result.d = ValD(ReadProgramString(prg))
      CloseProgram(prg)
      ProcedureReturn result ; success
    Else
      ProcedureReturn 0 ; scripting host failure
    EndIf
  Else
    ProcedureReturn 0 ; CreateFile failure
  EndIf
EndProcedure

Debug Evaluate("47+2*10/3")

which is probably the shortest and most powerful solution. The scripting host can do anything VBScript is capable of, which is quite a lot.

_________________
Veni, vidi, vici.


Last edited by netmaestro on Mon Dec 11, 2006 1:54 pm, edited 5 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 1:31 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7445
Location: Norway
You forgot CloseProgram()


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 1:36 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
Quite right, thanks for pointing it out. Should be reasonably correct now. Also, it doesn't seem to need #PB_Program_Hide.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 1:40 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> Should be reasonably correct now

Well, technically the "If prg" block should go inside the "If CreateFile" block,
because if the file was never created then there's no need to do an "If prg"
check. ;) Also, I'd make the code create the file in the TEMP dir, so the user
is never aware of it.

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 1:43 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
No, you have to make a separate check, to cover two eventualities: couldn't create the file, couldn't load the scripting host. Agreed on the TEMP dir though, good idea. I'm also looking to see if I can stream the command line into the host, no file needed. Should be doable, if anyone knows how, pls post before I spend a lot of time on it :wink:

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 1:48 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> two eventualities: couldn't create the file, couldn't load the scripting host

Yes, but if CreateFile fails, there's no need to check "prg". But if CreateFile
worked, then you can go ahead and check "prg" in the same block, so both
cases are covered with only one decision and not two.

Here's two "Visustin" flowcharts to show what I mean:

http://img15.imgspot.com/?u=/u/06/344/19/Image11165881937.gif

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Last edited by PB on Tue Dec 12, 2006 12:15 am, edited 5 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 1:52 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8027
Location: Fort Nelson, BC, Canada
You win. It does have a cleaner feel to it. Updated.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 2:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 12, 2006 7:59 pm
Posts: 171
Location: Germany
Not nice, but the result is correct (PB 4.0 or higher):
Code:
Debug ValD(StrD((ValD("47") + ValD("2") * ValD("10") / ValD("3"))))

Gruss
Helle


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 11, 2006 2:40 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Aug 15, 2003 3:46 am
Posts: 164
Location: Canada
thank you all for the replies, it will help me a lot.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Dec 12, 2006 12:17 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
@TheFool: I changed my link, just for you, to use ImgSpot to avoid the ads.

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Fred and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye