Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Oct 16, 2018 3:19 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 2:01 pm 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
Well i want to be able to type in the formula like this: ( (480*480 / 100) into the text box, and then return it's value with the below code via a push button:
dim formula as double
formula = val(TextField_graphics.Text)
MsgBox( str(formula) )


And then i want that formula to be executed like a math equation you know... and i see the results...
What i got from the above code is result: 0.

Any ideas ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 2:27 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
I did exactly this with a class based on RBScript. Basically, it turns your text into an RBScript, runs that script, then returns the value as a Variant. I designed it to be safe (no multiple lines or extra code allowed), but to understand functions and the like. Let me know if you want it.

Note that adding RBScript to your project increases the app size noticeably.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 2:38 pm 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
Im making a calculator for something personall, and i don't require speed nor size to be optimized.
And yes i would very appreciate if you gave me the script.

I am barely touching Real Studio, but i will more in the future, thus im really bad at it atm. (Getting my life together <.<... not an easy task <.<)


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 2:45 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
See here:

https://dl.dropbox.com/u/26920684/Evaluator.zip

Also included is an AppleScript-based Evaluator.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 3:14 pm 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
What if the program decides to say it cannot find the applescript ? What do i do then ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 3:15 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
Oh, that might be based on the MBS plugins. You can just delete that class.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 4:40 pm 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
Idk, if i delete it, then another 20 errors pop...


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sun Mar 10, 2013 4:51 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
Right, all in the test code. You can comment out those lines, or just examine them to see how the class should be used.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Mon Mar 11, 2013 4:20 am 
Offline

Joined: Fri Aug 31, 2012 3:56 pm
Posts: 82
Try: http://mac.rbytes.net/cat/development/d ... mathfield/


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Mon Mar 11, 2013 10:30 am 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
Thanks for both of your helps, much appreciated, the one that worked for me is the "jakuno"'s answer, all i need left is like 3 min work and calculator is done ^^, gona spare me hundreds of hours yay.

Programming is extremely usefull if you know how to use it :D.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Tue Mar 12, 2013 3:59 pm 
Offline
Site Admin
User avatar

Joined: Fri Sep 30, 2005 9:35 am
Posts: 987
Location: South Portland, Maine
There is an example included with Real Studio that does this. Check out:

Example Projects/Advanced/RBScript/RBScriptEvaluator.rbp

_________________
Paul Lefebvre
Developer Evangelist
Xojo, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Wed Mar 13, 2013 4:41 pm 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
Ironically i found it 2 minutes ago...


Also, is it possible to have variable names inside, and have their values be specified from within the code ???


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Wed Mar 13, 2013 6:29 pm 
Offline
Site Admin
User avatar

Joined: Fri Sep 30, 2005 9:35 am
Posts: 987
Location: South Portland, Maine
Primoz128 wrote:
Also, is it possible to have variable names inside, and have their values be specified from within the code ???

Sure, if you use RBScript in all its glory, you can pretty much do whatever you want.

_________________
Paul Lefebvre
Developer Evangelist
Xojo, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about formulas inside text boxes...
PostPosted: Sat Mar 16, 2013 6:29 am 
Offline

Joined: Sun Oct 21, 2012 10:47 am
Posts: 76
Location: Slovenia
I am interested what new features are coming for Real Studio in the next version the 2013R...

Cause Real Studio is just the best Software Development Tool there exists, it eats Microsoft's Visual Studio for breakfast, it's just so much better, i really hope Real Software keeps the good work going.




I tried modifying the Evaluator script to allow variables inside, but all i get is errors...
I tried the following:

Dim source As String

source = "Dim expr As Variant = " + expression + EndOfLine + _
"If expr.IsNumeric Then " + EndOfLine + _
"mResult = Str(expr.DoubleValue)" + EndOfLine + _
"Else If -expr.IsNumeric Then " + EndOfLine + _ // MINE
"mResult = expr" + EndOfLine + _ // MINE
"Else " + EndOfLine + _
"mResult = expr" +EndOfLine + _
"End If"

Self.Source = source
Self.Context = Self // So we can refer to Evaulator.mResult property in RBScript
Self.Run

Return mResult


Well im pretty newby coder <.<.

EDIT: Just never mind i got an easy idea how to do it <.<...


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

All times are UTC - 5 hours


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group