loop, parse, cant display values from file Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
DanRim
Posts: 77
Joined: 20 Jul 2018, 15:16

loop, parse, cant display values from file

30 Aug 2020, 12:54

Hello, AHK pros.
I cant display values from the file on my Gui.
I was following Helberts tutorial on youtube, but I am not sure why loop parse does not work on my Gui.
Everything is working except that Loop, parse part. Maybe some one could help me with this issue?

youtube tutorial:
https www.youtube.com /watch?v=4DaIsz-lTjU Broken Link for safety
time: 33:30

Code: Select all


#SingleInstance,Force
SetWorkingDir,%A_ScriptDir%\ahk_stuff
FileCreateDir, %A_ScriptDir%\ahk_stuff\Temp File Folder For Gui Mini Tut 21
SetWorkingDir,%A_ScriptDir%\ahk_stuff\Temp File Folder For Gui Mini Tut 21

Gui, Color, Black,FFB1B1

;    Delimited Area
;----------------------------------------------------------------------------
Gui, Add, Groupbox, x5 y+10 w290 h180 ,
Gui, Add, Text,cLime xp+10 yp+20 w20 h20 Section Border Center,1: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_1 gSubmit_All,
Gui, Add, Text,cB400FF xs  w20 h20 Border Center,2: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_2 gSubmit_All,
Gui, Add, Text,cLime xs  w20 h20 Border Center,3: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_3 gSubmit_All,
Gui, Add, Text,cB400FF xs  w20 h20 Border Center,4: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_4 gSubmit_All,
Gui, Add, Text,cLime xs  w20 h20 Border Center,5: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_5 gSubmit_All,
Gui, Add, Button, xs y+10 w125 h20  vButton4 gSave_Delimited_To_File,Save To File
Gui, Add, Button, x+20 w125 h20  vButton5 gLoad_Delimited_File,Load From File

;-------------------------------------------------------------------------

Gui,+AlwaysOnTop 
Gui, Show, x1400 y80 w300 h200,

Gui, Submit, NoHide
return

;                                LABELS
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

GuiClose:
	ExitApp

Submit_All:											
	Gui, Submit, NoHide	
	return

Save_Delimited_To_File:	
	FileDelete, Delimited.txt
	FileAppend, % EB_DS_1 "*" EB_DS_2 "*" EB_DS_3 "*" EB_DS_4 "*" EB_DS_5, Delimited.txt ; in file data will look like this 1*2*3*4*5
	return

Load_Delimited_File:	
	FileRead, Temp_File_Data, Delimited.txt
	Loop,Parse,Temp_File_Data,*												   
		{
			EB_DS_%A_Index% := A_LoopField
			GuiControl,,EB_DS_%A_Index%,% EB_DS_%A_Index%									
		}
	return


Esc::ExitApp




Attachments
parse_error.JPG
Loop parse does not working
parse_error.JPG (64.17 KiB) Viewed 227 times
garry
Posts: 2431
Joined: 22 Dec 2013, 12:50

Re: loop, parse, cant display values from file

30 Aug 2020, 14:25

try this

Code: Select all

#SingleInstance,Force
fd1=%A_ScriptDir%\ahk_stuff
fd2=%A_ScriptDir%\ahk_stuff\Temp File Folder For Gui Mini Tut 21
SetWorkingDir,%fd1%
FileCreateDir,%fd2%
SetWorkingDir,%fd2%
f1=%fd2%\Delimited.txt
;-- for test :
ifnotexist,%f1%
{
e=
(
1111a*2222b*3333333333c*4444d*55e
)
fileappend,%e%,%f1%
}
Gui, Color, Black,FFB1B1
;----------------------------------------------------------------------------
Gui, Add, Groupbox, x5 y+10 w290 h180 ,
Gui, Add, Text,cLime xp+10 yp+20 w20 h20 Section Border Center,1: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_1 ,
Gui, Add, Text,cB400FF xs  w20 h20 Border Center,2: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_2 ,
Gui, Add, Text,cLime xs  w20 h20 Border Center,3: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_3 ,
Gui, Add, Text,cB400FF xs  w20 h20 Border Center,4: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_4 ,
Gui, Add, Text,cLime xs  w20 h20 Border Center,5: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_5 ,
Gui, Add, Button, xs y+10 w125 h20  vButton4 gSave_Delimited_To_File,Save To File
Gui, Add, Button, x+20 w125 h20  vButton5 gLoad_Delimited_File,Load From File
;-------------------------------------------------------------------------
Gui,+AlwaysOnTop 
Gui, Show, x1400 y80 w300 h200,
gosub,Load_Delimited_File
return
;-----------------
GuiClose:
ExitApp
;-----------------
Save_Delimited_To_File:	
Gui,submit,nohide
	FileDelete, %f1%
	FileAppend, % EB_DS_1 "*" EB_DS_2 "*" EB_DS_3 "*" EB_DS_4 "*" EB_DS_5,%f1% ; in file data will look like this 1*2*3*4*5
	return
Load_Delimited_File:	
	FileRead, Temp_File_Data,%f1%
	Loop,Parse,Temp_File_Data,*												   
		{
			EB_DS_%A_Index% := A_LoopField
			GuiControl,,EB_DS_%A_Index%,% EB_DS_%A_Index%									
		}
	return
;==================================================================
BoBo
Posts: 3757
Joined: 13 May 2014, 17:15

Re: loop, parse, cant display values from file

30 Aug 2020, 14:42

Code: Select all

#SingleInstance,Force
SetWorkingDir,% A_ScriptDir				; \ahk_stuff
FileCreateDir,% A_ScriptDir				; \ahk_stuff\Temp File Folder For Gui Mini Tut 21
SetWorkingDir,% A_ScriptDir				; \ahk_stuff\Temp File Folder For Gui Mini Tut 21

Gui, Color, Black,FFB1B1

Gui, Add, Groupbox, x5 y+10 w290 h180 ,
Gui, Add, Text,cLime xp+10 yp+20 w20 h20 Section Border Center	,1: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_1						, bla    ; values set for testing. To be removed
Gui, Add, Text,cB400FF xs  w20 h20 Border Center				,2: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_2						, blu
Gui, Add, Text,cLime xs  w20 h20 Border Center					,3: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_3						, blo
Gui, Add, Text,cB400FF xs  w20 h20 Border Center				,4: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_4						, bli
Gui, Add, Text,cLime xs  w20 h20 Border Center					,5: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_5						, blub
Gui, Add, Button, xs y+10 w125 h20  vButton4 gSubmit_All		,Save To File
Gui, Add, Button, x+20 w125 h20  vButton5 gLoad_Delimited_File	,Load From File
Gui,+AlwaysOnTop 
Gui, Show, x10 y10 w300 h200,
Return

Submit_All:											
	Gui, Submit, NoHide
	FileDelete, Delimited.txt
	FileAppend, % EB_DS_1 "*" EB_DS_2 "*" EB_DS_3 "*" EB_DS_4 "*" EB_DS_5, Delimited.txt ; in file data will look like this 1*2*3*4*5
	Loop 5
		GuiControl,, EB_DS_%A_Index%		; get rid of the entries so you're able to realize ...
	Return

Load_Delimited_File:	
	FileRead, Temp_File_Data, Delimited.txt
	Loop,Parse,Temp_File_Data,*												   
		{
			EB_DS_%A_Index% := A_LoopField
			GuiControl,, EB_DS_%A_Index%,% EB_DS_%A_Index%	; ... the re-entry of those values.								
		}
	Gui, Show
	Return

GuiEscape:
GuiClose:
	ExitApp
DanRim
Posts: 77
Joined: 20 Jul 2018, 15:16

Re: loop, parse, cant display values from file  Topic is solved

31 Aug 2020, 14:21

The problem was with file path. instead of seting Delimited.txt i just typed:
C:\Users\Admin\Desktop\ahk_stuff\Temp File Folder For Gui Mini Tut 21\Delimited.txt

I am not sure why this approach worked, but it worked.

Thanks for your time guys.
garry
Posts: 2431
Joined: 22 Dec 2013, 12:50

Re: loop, parse, cant display values from file

01 Sep 2020, 01:37

that means you started the script at desktop and there creates > folder\subfolder
but you can define the path like > C:\Test1\ahk_stuff\Temp File Folder For Gui Mini Tut 21\Delimited.txt
example above worked but creates always the folders > %A_ScriptDir%\ahk_stuff\Temp File Folder For Gui Mini Tut 21 , depending where you start the script
BoBo's example works also fine , Delimited.txt is in a_scriptdir , the variables are in the GUI , save the variables to > %a_scriptdir%\Delimited.txt and clear EDIT-fields

Code: Select all

;- create folder\subfolder 
#SingleInstance,Force
fd1=C:\TEST1\ahk_stuff
fd2=%fd1%\Temp File Folder For Gui Mini Tut 21
SetWorkingDir,%fd1%
FileCreateDir,%fd2%
SetWorkingDir,%fd2%
f1=%fd2%\Delimited.txt
;-- for test :
ifnotexist,%f1%
{
e=
(
1111a*2222b*3333333333c*4444d*55e
)
fileappend,%e%,%f1%
}
Gui, Color, Black,FFB1B1
;----------------------------------------------------------------------------
Gui, Add, Groupbox, x5 y+10 w290 h180 ,
Gui, Add, Text,cLime xp+10 yp+20 w20 h20 Section Border Center,1: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_1 ,
Gui, Add, Text,cB400FF xs  w20 h20 Border Center,2: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_2 ,
Gui, Add, Text,cLime xs  w20 h20 Border Center,3: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_3 ,
Gui, Add, Text,cB400FF xs  w20 h20 Border Center,4: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_4 ,
Gui, Add, Text,cLime xs  w20 h20 Border Center,5: 
Gui, Add, Edit, x+20  w220 h20  vEB_DS_5 ,
Gui, Add, Button, xs y+10 w125 h20  vButton4 gSave_Delimited_To_File,Save To File
Gui, Add, Button, x+20 w125 h20  vButton5 gLoad_Delimited_File,Load From File
;-------------------------------------------------------------------------
Gui,+AlwaysOnTop 
Gui, Show, x1400 y80 w300 h200,
gosub,Load_Delimited_File
return
;-----------------
GuiClose:
ExitApp
;-----------------
Save_Delimited_To_File:	
Gui,submit,nohide
	FileDelete, %f1%
	FileAppend, % EB_DS_1 "*" EB_DS_2 "*" EB_DS_3 "*" EB_DS_4 "*" EB_DS_5,%f1% ; in file data will look like this 1*2*3*4*5
    Loop 5
		GuiControl,1:, EB_DS_%A_Index%		; get rid of the entries so you're able to realize ...
	return
Load_Delimited_File:	
	FileRead, Temp_File_Data,%f1%
	Loop,Parse,Temp_File_Data,*												   
		{
			EB_DS_%A_Index% := A_LoopField
			GuiControl,,EB_DS_%A_Index%,% EB_DS_%A_Index%									
		}
	return
;==================================================================

DanRim
Posts: 77
Joined: 20 Jul 2018, 15:16

Re: loop, parse, cant display values from file

01 Sep 2020, 07:52

@garry Thank you for explaining!

Return to “Ask For Help”

Who is online

Users browsing this forum: electrone77, mmmax, nacken012, prakharguptaujn, RubbeH, schakrob, Xtra and 46 guests