AHK-v2-script-converter
AHK-v2-script-converter copied to clipboard
FileReadLine
can replace
FileReadLine, line, C:\My Documents\ContactList.txt, 5
with
Loop, Read, C:\My Documents\ContactList.txt
{
if (A_Index = 5)
{
line := A_LoopReadLine
break
}
}
or using file objects
file := FileOpen("C:\My Documents\ContactList.txt", "r")
Loop 5
line := file.ReadLine()
file.Close()
what about this from the v1 help file?
Loop
{
FileReadLine, line, C:\My Documents\ContactList.txt, %A_Index%
if ErrorLevel
break
MsgBox, 4, , Line #%A_Index% is "%line%". Continue?
IfMsgBox, No
return
}
that would mean something like this
Loop
{
i := A_Index
Loop, Read, C:\My Documents\ContactList.txt
{
if (A_Index = i)
{
line := A_LoopReadLine
break
}
}
if ErrorLevel
break
MsgBox, 4, , Line #%A_Index% is "%line%". Continue?
IfMsgBox, No
return
}
but this code is also checking ErrorLevel, really not any good solution
This is the correct conversion (not yet implemented) if ErrorLevel is not present in the script, we can skip the setting of it.
try{
ErrorLevel := 0
Text_FileRead := FileRead("C:\Users\Dimitri\Documents\FTsPLog.txt")
line := StrSplit(Text_FileRead,"n","
r")[A_Index]
} Catch{
line := ""
ErrorLevel := 1
}