Array syntax Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stepanVL
Posts: 11
Joined: 27 Jun 2017, 08:56

Array syntax

27 Jun 2017, 13:06

I've tried several ways to use Loop, read %arrayName[arrayIndex]%, but none of them work. What is the correct syntax?

Code: Select all

param := []
param[1] := "C:\folder\a.txt"
param[2] := "C:\folder\b.txt"
i:=1
source := param[i]

; Loop, read,   param[i]  ; fails because string is treated literally
; Loop, read,   param%i% ; fails because string is treated literally
; Loop, read,   %param[i]% ; fails somehow
; Loop, read,   %%param[%i%]%% ; fails somehow

Loop, read,   %source% ; This works
	MsgBox % A_LoopReadLine
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Array syntax

27 Jun 2017, 13:39

Loop, Read,% param[1]
Force an expression: An expression can be used in a parameter that does not directly support it (except OutputVar parameters) by preceding the expression with a percent sign and a space or tab. In [v1.1.21+], this prefix can be used in the InputVar parameters of all commands except the traditional IF commands (use If (expression) instead). This technique is often used to access arrays. For example: ...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Array syntax  Topic is solved

27 Jun 2017, 13:53

Code: Select all

q::
obj := []
obj[1] := "C:\folder\a.txt"
obj[2] := "C:\folder\b.txt"
Loop, % obj.Length()
	MsgBox, % obj[A_Index]
for vKey, vValue in obj
	MsgBox, % vKey " " vValue
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
stepanVL
Posts: 11
Joined: 27 Jun 2017, 08:56

Re: Array syntax

27 Jun 2017, 14:31

jeeswg wrote:

Code: Select all

Loop, % obj.Length()
This answers the question. Thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, scriptor2016 and 358 guests