make a status bar that counts processed lines and number of source file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
crypter
Posts: 90
Joined: 15 Dec 2020, 09:57

make a status bar that counts processed lines and number of source file

Post by crypter » 20 Jun 2021, 17:10

i have this script, that i added a status bar to

it currently displays the total amount of max lines. i have to make it show live the number of processed lines (not total without counting)

i added this

Code: Select all

	Gui, Add, StatusBar,, Bar's starting text (omit to start off empty).
	SB_SetText("There are " . MaxLines . " lines total by " . SourceLines . " times.")

Code: Select all

#NoEnv
SetBatchLines, -1

SourcePaths := ["C:\New folder (3)\New folder\source5.txt"
	, "C:\New folder (3)\New folder\source4.txt"
	, "C:\New folder (3)\New folder\source3.txt"
	, "C:\New folder (3)\New folder\source2.txt"
	, "C:\New folder (3)\New folder\source1.txt"]
TargetPath := "C:\New folder (3)\New folder (2)" ; NO CLOSING \
TargetExt := "txt" ; File type

For Each, SourcePath in SourcePaths
{
	FileRead, SourceData, %SourcePath%
	SourceLines := StrSplit(SourceData, "`r`n")
	MaxLines := SourceLines.Length()  ; <-------- look below

	Gui, Destroy
	Gui, Add, StatusBar,, Bar's starting text (omit to start off empty).
	SB_SetText("There are " . MaxLines . " lines total by " . SourceLines . " times.")
	Gui,Add,Progress,x10 y10 w461 range0-%MaxLines% vMyProgressBar   ; <-------- We need to know the MaxLines variable before Progress bar is built
	Gui,Show

	Loop Files, %TargetPath%\*.%TargetExt%
	{
	If (A_Index > MaxLines)
		ErrorExit("More files than source lines (" . MaxLines . ")!")
	If !(FileObj := FileOpen(A_LoopFileLongPath, "rw"))
		ErrorExit("Could not open the target file " . A_LoopFileLongPath . "!")
	FileContent := FileObj.Read()
	If (Pos := RegExMatch(FileContent, "Pim)^\[content\]$", Len)) {
		FileObj.Pos := Pos + Len - 1
		FileObj.Write("`r`n" . SourceLines[A_Index])
		FileObj.Write(SubStr(FileContent, Pos + Len))
		GuiControl,,MyProgressBar, +1
	}
	FileObj.Close()
	If (Pos = 0)
		ErrorExit(A_LoopFileLongPath . "`r`ncould not find the [content] line!")
	}
}

ErrorExit(Msg) {
   MsgBox, 16, ERROR!, %Msg%
   ExitApp
}
it has to be like in the screenshot below
Attachments
Capture.PNG
Capture.PNG (4 KiB) Viewed 362 times

crypter
Posts: 90
Joined: 15 Dec 2020, 09:57

Re: make a status bar that counts processed lines and number of source file

Post by crypter » 20 Jun 2021, 20:35

i attached the files required
Attachments
New folder (3).rar
(342.97 KiB) Downloaded 9 times


doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: make a status bar that counts processed lines and number of source file  Topic is solved

Post by doubledave22 » 21 Jun 2021, 15:31

You need to call SB_SetText somewhere in your Loop Files:

Code: Select all

#NoEnv
SetBatchLines, -1

SourcePaths := ["C:\New folder (3)\New folder\source5.txt"
	, "C:\New folder (3)\New folder\source4.txt"
	, "C:\New folder (3)\New folder\source3.txt"
	, "C:\New folder (3)\New folder\source2.txt"
	, "C:\New folder (3)\New folder\source1.txt"]
TargetPath := "C:\New folder (3)\New folder (2)" ; NO CLOSING \
TargetExt := "txt" ; File type

For Each, SourcePath in SourcePaths
{
	FileRead, SourceData, %SourcePath%
	SourceLines := StrSplit(SourceData, "`r`n")
	MaxLines := SourceLines.Length()  ; 
        Source_Index := a_index ; save which source path we are on

	Gui, Destroy
	Gui, Add, StatusBar,, Bar's starting text (omit to start off empty).
	SB_SetText("There are " . MaxLines . " lines total by " . SourceLines . " times.")
	Gui,Add,Progress,x10 y10 w461 range0-%MaxLines% vMyProgressBar
	Gui,Show

	Loop Files, %TargetPath%\*.%TargetExt%
	{
	If (A_Index > MaxLines)
		ErrorExit("More files than source lines (" . MaxLines . ")!")
	If !(FileObj := FileOpen(A_LoopFileLongPath, "rw"))
		ErrorExit("Could not open the target file " . A_LoopFileLongPath . "!")
	FileContent := FileObj.Read()
	If (Pos := RegExMatch(FileContent, "Pim)^\[content\]$", Len)) {
		FileObj.Pos := Pos + Len - 1
		FileObj.Write("`r`n" . SourceLines[A_Index])
		FileObj.Write(SubStr(FileContent, Pos + Len))
		GuiControl,,MyProgressBar, +1
	}
        SB_SetText("edited lines: " a_index "/" MaxLines " from source file " Source_Index  " of " SourceLines)
	FileObj.Close()
	If (Pos = 0)
		ErrorExit(A_LoopFileLongPath . "`r`ncould not find the [content] line!")
	}
}
I'm not sure I got all the variables right but it should get you closer

crypter
Posts: 90
Joined: 15 Dec 2020, 09:57

Re: make a status bar that counts processed lines and number of source file

Post by crypter » 02 Jul 2021, 01:20

i get an error for the script above
Attachments
scr2.PNG
scr2.PNG (25.55 KiB) Viewed 277 times

gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: make a status bar that counts processed lines and number of source file

Post by gregster » 02 Jul 2021, 01:43

It's obv missing a function called ErrorExit() - perhaps the one from your original post ?

Post Reply

Return to “Ask for Help (v1)”