Share your advanced PureBasic knowledge/code with the community.
Trond
Always Here
Posts: 7446 Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway
Post
by Trond » Thu Dec 07, 2006 4:23 pm
Code: Select all
Procedure.l Eval(String.s)
Protected Program.l, Result.l
Program = RunProgram("cmd", "/c set /a " + String, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
WaitProgram(Program)
Result = Val(ReadProgramString(Program))
CloseProgram(Program)
ProcedureReturn Result
EndProcedure
Debug Eval("5+2*10")
AND51
Addict
Posts: 1040 Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:
Post
by AND51 » Thu Dec 07, 2006 4:33 pm
Just 7 lines
Code: Select all
Procedure.l Eval(String.s)
Protected Program = RunProgram("cmd", "/c set /a " + String, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
WaitProgram(Program)
Protected Result = Val(ReadProgramString(Program))
CloseProgram(Program)
ProcedureReturn Result
EndProcedure
Debug Eval("5+2*10")
Nice idea, the example works.
Max
User
Posts: 67 Joined: Thu Nov 30, 2006 4:57 pm
Location: I long for the absolute loneliness of the death
Post
by Max » Thu Dec 07, 2006 4:34 pm
PB
PureBasic Expert
Posts: 7581 Joined: Fri Apr 25, 2003 5:24 pm
Post
by PB » Thu Dec 07, 2006 9:20 pm
Both versions don't work with floats (try 22/7) making them a bit useless.
Oh, and they don't work with Windows 9x/Me either, which may be an issue.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
dracflamloc
Addict
Posts: 1648 Joined: Mon Sep 20, 2004 3:52 pm
Contact:
Post
by dracflamloc » Thu Dec 07, 2006 9:53 pm
I doubt this was really intended to be taken seriously...
AND51
Addict
Posts: 1040 Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:
Post
by AND51 » Thu Dec 07, 2006 10:11 pm
I just copied the original code and I removed the first Protected-line.
Tested under XP, works.
Don't forget to try
command.com instead of
cmd.exe if you do not have XP ...
22/7 ? Not tested yet. I assume, that command/cmd cannot handle floats, just integers.
Trond
Always Here
Posts: 7446 Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway
Post
by Trond » Thu Dec 07, 2006 11:09 pm
... to think of?
PB wrote: Both versions don't work with floats (try 22/7) making them a bit useless.
Oh, and they don't work with Windows 9x/Me either, which may be an issue.
Not useless for integer expressions.
On the other hand, it supports hexadecimal and octal numbers.
But yes, I didn't think about the 9x problem. That's a real problem.
dracflamloc wrote: I doubt this was really intended to be taken seriously...
Yes, it's not exactly serious, but it actually can be used.
dracflamloc
Addict
Posts: 1648 Joined: Mon Sep 20, 2004 3:52 pm
Contact:
Post
by dracflamloc » Thu Dec 07, 2006 11:40 pm
Oh yes I know. Its kind of a neat hack. I didn't realize that you could do that with the set command.
va!n
Addict
Posts: 1104 Joined: Wed Apr 20, 2005 12:48 pm
Post
by va!n » Fri Dec 08, 2006 11:05 am
codelines size compo?
just 4 lines... ok, it could fit in one line
Code: Select all
Procedure.l Eval(String.s)
Protected Program = RunProgram("cmd", "/c set /a " + String, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide), Result = Val(ReadProgramString(Program))
WaitProgram(Program) And CloseProgram(Program) : ProcedureReturn Result
EndProcedure
Debug Eval("5+2*10")
va!n aka Thorsten
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Konne
Enthusiast
Posts: 434 Joined: Thu May 12, 2005 9:15 pm
Post
by Konne » Fri Dec 08, 2006 11:38 am
Doesn't work with unicode either.
Apart from that Mrs Lincoln, how was the show?
Heathen
Enthusiast
Posts: 498 Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..
Post
by Heathen » Fri Dec 08, 2006 9:23 pm
va!n wrote: codelines size compo?
just 4 lines... ok, it could fit in one line
Code: Select all
Procedure.l Eval(String.s)
Protected Program = RunProgram("cmd", "/c set /a " + String, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide), Result = Val(ReadProgramString(Program))
WaitProgram(Program) And CloseProgram(Program) : ProcedureReturn Result
EndProcedure
Debug Eval("5+2*10")
I love Purebasic.
utopiomania
Addict
Posts: 1655 Joined: Tue May 10, 2005 10:00 pm
Location: Norway
Post
by utopiomania » Fri Dec 08, 2006 11:46 pm
Trond, I posted:
Expression Evaluator in just 45 lines of code
Then you had to post:
Expression Evaluator in just 8 lines of code
Only mine is as useful to yours as 45 is to .00008!
What a sorry hack, I mean, Integer math only? No functions or variables? I doubt you can be a Norwegian after all.
Trond
Always Here
Posts: 7446 Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway
Post
by Trond » Fri Dec 08, 2006 11:57 pm
Well, you can use variables.
utopiomania
Addict
Posts: 1655 Joined: Tue May 10, 2005 10:00 pm
Location: Norway
Post
by utopiomania » Sat Dec 09, 2006 12:14 am
Ohh, variables, well, rocket science then!
PB
PureBasic Expert
Posts: 7581 Joined: Fri Apr 25, 2003 5:24 pm
Post
by PB » Sat Dec 09, 2006 12:45 am
> Ohh, variables, well, rocket science then!
That is the funniest pic I've seen in ages! A definite keeper!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.