Help turning a string into calling a variable Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
LepG
Posts: 2
Joined: 16 Apr 2024, 06:08

Help turning a string into calling a variable

16 Apr 2024, 06:21

Hey there, I'm writing a script and need to change a string into a variable, been looking for a while and can't find how to do this, it's a bit hard to explain so here's an example

Code: Select all


v1 := "q"
v2 := "e"
v3 := "r"

string := "123"

CurChar := SubStr(string, 1 , 1)

SendInput "{v" CurChar " Down}"

This is not my actual code, the code is too big to put here, this is just an example of what i'm trying to do. CurChar will get the first number of the string and I want to send the correspondent variable, so in the example above, the number is 1 so I would like to send "{" v1 " Down}" which equals {q Down}, if string was "213" it would send "{" v2 " Down}" which equals {e Down}. I know I probably could do it by using if statements but in my actual code I would need way to many if statements(unless there is a way to use them that i'm not sure of), so I was wondering if maybe there's a way to turn the string "v1" into the variable v1 or "v2" into the variable v2
gregster
Posts: 9036
Joined: 30 Sep 2013, 06:48

Re: Help turning a string into calling a variable  Topic is solved

16 Apr 2024, 07:10

Try this

Code: Select all

#Requires AutoHotkey v2.0
v1 := "q"
v2 := "e"
v3 := "r"

str := "123"
CurChar := SubStr(str, 1 , 1)

x::SendInput "{" %"v" CurChar% " down}"
string is a reserved word in v2, and can't be used as a variable name.
For dereference operations, there is %Expr%.
LepG
Posts: 2
Joined: 16 Apr 2024, 06:08

Re: Help turning a string into calling a variable

16 Apr 2024, 09:54

That worked perfectly, thank you!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww, XMCQCX and 72 guests