Variable into command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
KrycerKris
Posts: 10
Joined: 25 Sep 2017, 13:42

Variable into command

25 Sep 2017, 15:53

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?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Variable into command

25 Sep 2017, 17:02

A workaround to run code dynamically:
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
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Variable into command

26 Sep 2017, 05:19

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.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Variable into command

26 Sep 2017, 08:32

jeeswg wrote:A workaround to run code dynamically:
Run / RunWait
https://autohotkey.com/docs/commands/Run.htm#ExecScript
He's right, I use this all the time:

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
This is just an example.
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


Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Holarctic, jameswrightesq, Lem2001 and 412 guests