Add "row" number to text file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
emn174
Posts: 8
Joined: 09 Mar 2023, 11:54

Add "row" number to text file

Post by emn174 » 22 Mar 2023, 16:07

Hi, so I have a script which creates a new text file in a folder every time I input survey responses. The text being inputted has multiple rows (copying example below), I wanted to know if there is any way to make the script add a number to each row of text in the text file outputted?

Thanks!
--------
Example input:
URL'
https://www.bls.gov/oes/current/oes_stru.htm
Source: (e.g. World Bank)'
BLS
Name: (e.g. Census of Population and Housing)'
Occupational Employment and Wage Statistics
Countries of coverage - separate multiple responses with ";"'
USA
Type'
Dataset
Quick description'
Labor data by occupation
Who found it? - include multiple people by separating them with a ";"'
Enrique
How would you like to tag this source? - Use ";" if you want to use multiple tags: e.g. "Public Finance; Demographics"'
Labor
Other notes?'
left blank
--------

Code: Select all

[/^q::
TrayTip Planck, ^q
Gui, Add, Edit, R10 W350 vMyInput
Gui, Add, Button, gShowText, Log
GuiControl, Hide, Log[/color]
Gui, Show, w400 h200
Return
ShowText:
{	
	GuiControlGet MyInput
	MsgBox %MyInput%
}
date=% A_YYYY A_MM A_DD A_Hour A_Min A_Sec
FileAppend ,%MyInput%, C:\Users\Enrique Monge\Box Sync\Latam source thingamabob\%date%.txt
GuiClose: 
ButtonLog: 
Gui, Submit
Gui, Destroy
Return
Return]

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Add "row" number to text file

Post by mikeyww » 22 Mar 2023, 19:46

Hello,

Here is an example of how to parse by line.

https://www.autohotkey.com/docs/v1/lib/LoopParse.htm#ExClipboard

Inside the loop, A_Index represents the iteration number, so you can then append that number followed by the line.

emn174
Posts: 8
Joined: 09 Mar 2023, 11:54

Re: Add "row" number to text file

Post by emn174 » 23 Mar 2023, 13:02

Thank you for your response! Is there any chance you could share example script to add that to my current script? Just need 1 number per text row. I understand A_Index is the variable, but tbh very new to authotkey scripts so unsure how to modify the script

Thanks!

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: Add "row" number to text file

Post by mikeyww » 23 Mar 2023, 13:37

Code: Select all

#Requires AutoHotkey v1.1.33
log := A_ScriptDir "\out.log"
Gui Font, s10
Gui Add, Edit, r10 w350 vtxt
Gui Add, Button, wp, Log
Gui Show
Return

ButtonLog:
Gui Submit
; FileRecycle % log
Loop Parse, % txt, `n, `r
 FileAppend % A_Index " " A_LoopField "`n", % log
Run % "notepad " log
Return

emn174
Posts: 8
Joined: 09 Mar 2023, 11:54

Re: Add "row" number to text file  Topic is solved

Post by emn174 » 29 Mar 2023, 16:03

Thank you all, in the end this is my final code developed, in case it helps anyone with a similar need.

Code: Select all

^q::
TrayTip Planck, ^q
Gui, Add, Edit, R10 W350 vMyInput
Gui, Add, Button, x370 y5 w40 h25 gAddRow, Add
Gui, Add, Button, x370 y35 w40 h25 gLog, Log
Gui, Show, w420 h100, My Input
GuiControl, Focus, MyInput1
row := 1
Return

AddRow:
    row += 1
    Gui, Add, Edit, R10 W350 vMyInput%row% y=row*25+10
    GuiControl, Move, MyInput%row%, x50 y=row*25+10 w270 h20
    GuiControl, Focus, MyInput%row%
    Return

Log:
    GuiControlGet, MyInput
    Gui, Submit
    Gui, Destroy
    row := 1
    Loop, Parse, MyInput, `n
    {
        date := A_YYYY . A_MM . A_DD . A_Hour . A_Min . A_Sec
        fileAppend, Row %row%`: %A_LoopField%`n, C:\Users\Enrique Monge\Box Sync\Latam source thingamabob\%date%_rows.txt
        row++
    }
    Return

#IfWinActive, Input
    Enter::
        Send, {Enter}
        Gui, Submit
        GuiControl, Focus, MyInput%row%
        row += 1
        Gui, Add, Edit, R10 W350 vMyInput%row% y=row*25+10
        GuiControl, Move, MyInput%row%, x50 y=row*25+10 w270 h20
        GuiControl, Focus, MyInput%row%
    Return
#IfWinActive

Post Reply

Return to “Ask for Help (v1)”