Read txt file save content of each line in variable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ras
Posts: 13
Joined: 25 Dec 2016, 11:52

Read txt file save content of each line in variable

17 Jul 2018, 04:23

I have a txt file i want to read content of each and save it into a variable
For eg :- read file1.txt, line1 is saved in variable1
Line2 in variable 2
And so on

Pls hlp in baby steps
Guest

Re: Read txt file save content of each line in variable

17 Jul 2018, 04:35

Fileread document into variable

Have a look at the https://autohotkey.com/docs/commands/StringSplit.htm command and function. Split on `n be sure to omit `r

Try something post code if you get stuck.

Alternatively you can use a parsing loop - https://autohotkey.com/docs/commands/LoopParse.htm - (see example #2)
ras
Posts: 13
Joined: 25 Dec 2016, 11:52

Re: Read txt file save content of each line in variable

17 Jul 2018, 08:58

Code: Select all

pFile :="pass.txt"
oTexto := Object()   
oFile := FileOpen(pFile,"r")   
If (!IsObject(oFile)) {      
	Msgbox 0x40000,,  % "ERROR Opening file " pFile
	ExitApp
}

While (!oFile.AtEOF) {       
  oTexto[A_index] := RegExReplace(oFile.ReadLine(),"\v+")   
}   

oFile.Close() 

run prefix %oTexto1% open_this_on_coordinates_x1y1 postfix 
run prefix %oTexto2%  open_this_on_coordinates_x2y2 postfix 
run prefix %oTexto3% open_this_on_coordinates_x3y3 postfix 
run prefix %oTexto4% open_this_on_coordinates_x4y4 postfix 
run prefix %oTexto5% open_this_on_coordinates_x5y5 postfix 
,
,
,
run prefix %oTexto10% open_this_on_coordinates_x10y10 postfix 
my run command is not running because neither %otexto1% nor %otext[1]%
pls help
ras
Posts: 13
Joined: 25 Dec 2016, 11:52

Re: Read txt file save content of each line in variable

17 Jul 2018, 09:06

alternative is i make one more txt file containing "open_this_on_coordinates_x1y1" values
then
read from both files
then
loop % otext0.maxindex()
{
run prefix otexto[A_index] ptestp[A_index] postfix
sleep 25 sec
}
as both files will always contain 10 lines so no problem will occur acc to me
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Read txt file save content of each line in variable

20 Jul 2018, 11:01

Unless you really want to make it an object, just use the Loop, Read, pass.txt and save it that way.
For example

Code: Select all

Loop, Read, pass.txt
Line%A_Index% := A_LoopReadLine

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333 and 331 guests