Variable into command
-
- Posts: 10
- Joined: 25 Sep 2017, 13:42
Variable into command
I have my script read a line from a file. How can I make the thing it reads into a command? To make AHK execute it, for example the file reads "C:=(A-32)", how can I make the script do the thing it reads?
Re: Variable into command
A workaround to run code dynamically:
Run / RunWait
https://autohotkey.com/docs/commands/Run.htm#ExecScript
Run / RunWait
https://autohotkey.com/docs/commands/Run.htm#ExecScript
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Variable into command
Maybe look for some kind of Eval() function?
Use
Code: Select all
[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: Variable into command
He's right, I use this all the time:jeeswg wrote:A workaround to run code dynamically:
Run / RunWait
https://autohotkey.com/docs/commands/Run.htm#ExecScript
Code: Select all
; ExecScript: Executes the given code as a new AutoHotkey process.
ExecScript(Script, Wait:=true)
{
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
exec.StdIn.Write(script)
exec.StdIn.Close()
if Wait
return exec.StdOut.ReadAll()
}
; Example:
InputBox expr,, Enter an expression to evaluate as a new script.,,,,,,,, Asc("*")
result := ExecScript("FileAppend % (" expr "), *")
MsgBox % "Result: " result
You can manipulate this and the main script (Keep the function) and use it the way you want.
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
Who is online
Users browsing this forum: Google [Bot], OrangeCat and 285 guests