AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to transform a "normal" variable into an expre

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Jun 18, 2005 5:34 am    Post subject: How to transform a "normal" variable into an expre Reply with quote

Hello.
I am trying to transform a variable like "var1 =2*2+2" into "var1 := 2*2+2".
Actually, I already did it but with a too long code, Is there some nice trick to do it with only a few lines?
Back to top
Rabiator



Joined: 17 Apr 2005
Posts: 271
Location: Sauerland

PostPosted: Sat Jun 18, 2005 7:15 am    Post subject: Re: How to transform a "normal" variable into an e Reply with quote

Anonymous wrote:
Hello.
I am trying to transform a variable like "var1 =2*2+2" into "var1 := 2*2+2".
Actually, I already did it but with a too long code, Is there some nice trick to do it with only a few lines?

Code:
; Replace
sText = var1 =2*2+2
MsgBox,, Original Text, %sText%
StringReplace, sExp, sText, =, :=, All
Msgbox,, Expression, %sExp%

; If you want to execute it:
FileDelete, new.ahk
FileAppend, %sExp%`n, new.ahk
FileAppend, MsgBox `%var1`%`n, new.ahk
RunWait, new.ahk
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Jun 18, 2005 8:43 pm    Post subject: Reply with quote

Hello. Thanks for your awser,but let me explain my problem with more details.
I have a gui window with many controls,one of then is a edit control.
In this edit I will write something like this "2*3+4".
I want the result (10) to be added to another edit contents,and I am looking for a way to do it using only one script.

with this lines of code:
Gui, Add, Edit, vMyEdit, 2*3+4
Gui, Add, Edit, vMyEdit2, 10
Gui, Add, Button, ,OK

when button OK is clicked it will send the "submit, nohide" command, but the variable
MyEdit contains a string ("2*3+4") not the result (10),and references to operators are considered "text" I presume.
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Jun 19, 2005 12:06 am    Post subject: Reply with quote

For reasons of performance and code-size reduction, it is not currently possible to dynamically evaluate an expression. For example, you can't do Result := %VarContainingExpression%.

Therefore, the script would either have to parse the expression and evaluate it on its own (quite a lot of complexity if you want to support parentheses, etc.) or you have to build and execute a second script as Rabiator suggested.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Sun Jun 19, 2005 12:30 am    Post subject: Reply with quote

Thx, Smile ,I was just ckecking if I missed some language command.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group