for loop not Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dave4033
Posts: 2
Joined: 05 Feb 2023, 14:39

for loop not

Post by dave4033 » 05 Feb 2023, 16:17

Hello
I have written this code (day 2 of ahk)
my needs are that:
  • it checks a file "log.txt" (top code block)
  • if the file is not blank it will loop through each line
  • paste each line in a website
  • delete the contents at the end
I cant get the for loop to fire, I have looked at loop but have had zero luck there too.
Can anyone help?
Please ignore my click on screen coords I want to click a specific window but that is my next item to learn on my list

Code: Select all

test-data-6537
data-test-3676
3674-data-test
12234-test-data

Code: Select all

#persistent

blankFile := ""
setTimer, checkFile, 20
return

checkFile:
fileread modifiedFile, log.txt

if(modifiedFile != blankFile) 
{
    for data in %modifiedFile%
    {
        CoordMode, mouse, Screen
        MouseClick, left, 1566, 512, 2
        Send, %data%
        MouseClick, left, 1586, 672
        MouseClick, left, 1558, 839
    }
    FileCopy, blank.txt, log.txt, 1
}
return

User avatar
Datapoint
Posts: 294
Joined: 18 Mar 2018, 17:06

Re: for loop not  Topic is solved

Post by Datapoint » 05 Feb 2023, 16:49

Here's a demo showing a parsing loop and a for-loop. The for loop takes an object as input, so I used StrSplit to split the string into individual lines to create the object.

Code: Select all

; AHK version 1.1
modifiedFile := "test-data-6537`r`ndata-test-3676`r`n3674-data-test`r`n12234-test-data"

; A parsing loop can loop through a string
Loop, Parse, modifiedFile, `n, `r
{
	MsgBox, 64, Parsing Loop,  % "Line Number: " A_Index "`nLine Data: " A_LoopField
}

; or with a for-loop

; Split the string (modifiedFile) and create an array (Lines)
Lines := StrSplit(modifiedFile, "`n", "`r")

; This is how to show line number x 
x := 2
MsgBox, 64, Line Number Two, % "Line Number: " x "`nLine Data: " Lines[x]

; for-loops require an array object (in this case, Lines)
for LineNumber, LineData in Lines
{
	MsgBox, 64, For-Loop,  % "Line Number: " LineNumber "`nLine Data: " LineData
}

dave4033
Posts: 2
Joined: 05 Feb 2023, 14:39

Re: for loop not

Post by dave4033 » 05 Feb 2023, 18:10

Datapoint wrote: Here's a demo showing a parsing loop ...
Many thanks I quickly got the for loop working from this and I will probably experiment with the parsing loop tomorrow

Post Reply

Return to “Ask for Help (v1)”