Create variables within loop, use them after loop ends Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lumpy
Posts: 21
Joined: 17 Mar 2017, 09:10

Create variables within loop, use them after loop ends

26 Jun 2017, 08:30

Hi all!
I don't know, how could I use my variables which are created within a loop, outside of the loop. The first MsgBox give me the content, but the 2nd one doesn't (t1).
Thank you!

Code: Select all

SetTitleMatchMode, 2
Loop, read, The.txt
{
    StringSplit, LineArray, A_LoopReadLine, `n
  	name := LineArray1
    email := LineArray2
    address := LineArray3
	szuli :=  LineArray4
	t1 := LineArray5
	code := LineArray6
    MsgBox, Fields are %name% %contact% %address% %t1% %code%
}
v1 := A_Hour A_Min
MsgBox, %v1% %t1%
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Create variables within loop, use them after loop ends

26 Jun 2017, 08:54

Your code splits the contents of the current line in the loop instead of of the file-content.
Try

Code: Select all

FileRead, Contents, The.txt
if not ErrorLevel  ; Successfully loaded.
{
    StringSplit, LineArray, Contents, `n
  	name := LineArray1
    email := LineArray2
    address := LineArray3
}
MsgBox, Fields are:`n`nname = %name%`ncontact = %email%`naddress = %address%
lumpy
Posts: 21
Joined: 17 Mar 2017, 09:10

Re: Create variables within loop, use them after loop ends

26 Jun 2017, 09:30

GEV wrote:Your code splits the contents of the current line in the loop instead of of the file-content.
Try

Code: Select all

FileRead, Contents, The.txt
if not ErrorLevel  ; Successfully loaded.
{
    StringSplit, LineArray, Contents, `n
  	name := LineArray1
    email := LineArray2
    address := LineArray3
}
MsgBox, Fields are:`n`nname = %name%`ncontact = %email%`naddress = %address%
Thank for your help, it works!
Unfortunately, now the variables contain the line feed, which is cause an error massage, which says
" The following variable contains an illegal character:"1625
"
How can I fix it?
Guest

Re: Create variables within loop, use them after loop ends  Topic is solved

26 Jun 2017, 09:47

Or use the IGNORE char option e.g. StringSplit, LineArray, Contents, `n, `r so it omits R from the variable.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Create variables within loop, use them after loop ends

26 Jun 2017, 09:56

Try replacing
StringSplit, LineArray, Contents, `n
with
StringSplit, LineArray, Contents, `r, `n

It removes the CRLF from the variable.
lumpy
Posts: 21
Joined: 17 Mar 2017, 09:10

Re: Create variables within loop, use them after loop ends

27 Jun 2017, 01:38

Guest wrote:Or use the IGNORE char option e.g. StringSplit, LineArray, Contents, `n, `r so it omits R from the variable.
Thank you for your help! :wave:
lumpy
Posts: 21
Joined: 17 Mar 2017, 09:10

Re: Create variables within loop, use them after loop ends

27 Jun 2017, 01:39

GEV wrote:Try replacing
StringSplit, LineArray, Contents, `n
with
StringSplit, LineArray, Contents, `r, `n

It removes the CRLF from the variable.
Thank you for your help! ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5 and 205 guests