Page 1 of 1

Assign array value

Posted: 17 Oct 2019, 15:51
by Sid4G
How to make this work?

Code: Select all

array := []
fileRead, array[1], test.txt

Re: Assign array value

Posted: 17 Oct 2019, 17:27
by Hellbent
I have never been able to get that to work and I've tried what has to be every possible way to force an expression.

I always just end up doing something like this.

Code: Select all

array := []
fileRead, temp, test.txt
array[1]:=temp
temp:=""
If someone does know how to get it to work I'd love to see it.

Re: Assign array value

Posted: 17 Oct 2019, 22:01
by gregster
It's simply not supported for Outputvars, only for Inputvars.

By accident, I just came across the corresponding part of the docs that mentions it:
https://www.autohotkey.com/docs/Variables.htm#Expressions wrote: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). For example:

Code: Select all

FileAppend, % MyArray[i], My File.txt

Re: Assign array value

Posted: 18 Oct 2019, 08:35
by Odlanir
Using pseudo-array ?

Code: Select all

myList := StrSplit("File001,File002,NewFile,LastFile",",")
for i,k in myList {
   fileRead, temp%i%, % k ".txt"   
}
Loop, %i% {
   x := A_Index
   str .= temp%x% "`n-----------------------------`n"
}
MsgBox % RTrim(str, "`n")