Assign array value

Get help with using AutoHotkey and its commands and hotkeys
Sid4G
Posts: 43
Joined: 02 Apr 2016, 19:11

Assign array value

17 Oct 2019, 15:51

How to make this work?

Code: Select all

array := []
fileRead, array[1], test.txt
Hellbent
Posts: 740
Joined: 23 Sep 2017, 13:34

Re: Assign array value

17 Oct 2019, 17:27

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.
gregster
Posts: 3295
Joined: 30 Sep 2013, 06:48

Re: Assign array value

17 Oct 2019, 22:01

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
Odlanir
Posts: 538
Joined: 20 Oct 2016, 08:20

Re: Assign array value

18 Oct 2019, 08:35

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")
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask For Help”

Who is online

Users browsing this forum: Cra44er, Google [Bot], hasantr, mehrez1989, rtepub, ulraf and 204 guests