 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sat Jun 18, 2005 5:34 am Post subject: How to transform a "normal" variable into an expre |
|
|
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
|
Posted: Sat Jun 18, 2005 7:15 am Post subject: Re: How to transform a "normal" variable into an e |
|
|
| 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 |
|
 |
Guest
|
Posted: Sat Jun 18, 2005 8:43 pm Post subject: |
|
|
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
|
Posted: Sun Jun 19, 2005 12:06 am Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Sun Jun 19, 2005 12:30 am Post subject: |
|
|
Thx, ,I was just ckecking if I missed some language command. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|