I'm trying to build a GUI that can be fed a dynamic number of inputs(read from a file) and have it display them for editing and then save back to file.
I'm not sure this is best but i'm trying to adapt my code from AHK_L so it's kinda bumpy so i've made this simplified version to try and help to diagnose what I'm doing wrong.
I think my primary issue is that i do not know how to assign a dynamic variable to a GUI control, which i need to do so that the gui can handle 10 20 or 50 items with connected variables. However, i do not know how to save them with the AHK v2 output system which seems to use a OOP style that i know very little about. (it's possible i'm just looking at the wrong version of AHK's manual and it's all there but maybe not and i could really use help to save me time from someone that knows.)
here is my code (i'm using "2.0-alpha")
"cfg.ini"
Code: Select all
"cfg.ini"
[Info]
PartCount=5
[1]
Name=AutoCompile
File=CMS_Part_Recompiler.ahk
[2]
Name=Attributes
File=CMS_Part_Attributes.ahk
[3]
Name=Globals
File=CMS_Part_Globals.ahk
[4]
Name=Setup
File=CMS_Func_Setup.ahk
[5]
Code: Select all
#SingleInstance force
global PartCount
global names := Object(), files := Object()
MsgBox(A_AhkVersion)
GoGUI:
gui := GuiCreate() ;create gui-obj
PartCount := IniRead("cfg.ini", "Info", "PartCount") ;reading ini file to get the number of entries to make for this gui
loop partcount ;loop for each part line of the gui
{
names.Push(iniread("cfg.ini", A_Index,"Name")) ;reads data from file for gui population
files.Push(iniread("cfg.ini", A_Index,"File")) ;reads data from file for gui population
;;;;;;;;;;;;;;;;;;;;;;; THIS IS THE SECTION THAT I THINK NEEDS HELP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gui.add( "text", "xm" , A_Index)
gui.add( "edit", "x+m vnames[" . A_Index . "]" , names[A_Index])
gui.add( "edit", "x+m vfiles[" . A_Index . "]" , files[A_Index])
;;;;;;;;;;;;;;;;;;;;;;; THIS IS THE SECTION THAT I THINK NEEDS HELP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
SubSave := Func("BtnSave").bind(gui) ;binds 'btnSave' function with the gui-obj for latter form submission
gui.add( "Button","xm" ,"Save").OnEvent("Click",SubSave) ;adds button and links 'btnSave' function to it when clicked
gui.show() ;shows the gui
Return
BtnSave(gui){
saved := gui.submit() ;should store variables from the gui all inside "saved" object as i understand
loop PartCount ;loops for each entry in the gui for to save back to file
{
txt := "debug output:`r`n" ;sets up a debug txt for me to check what i'm attempting to "save" to file
txt .= A_Index . " " . saved.files[A_Index] . "`r`n"
txt .= A_Index . " " . saved.names[A_Index] . "`r`n"
MsgBox(txt) ;msgbox with debug text
TransName := saved.names[A_Index] ;bouces the object info into another variable
TransFile := saved.files[A_Index] ;(this was my work around for "contains illegal characters")
IniWrite(TransName, "cfg.ini", A_Index, "Name") ;writes data to file
IniWrite(TransFile, "cfg.ini", A_Index, "File") ;writes data to file
}
gosub GoGUI ;reloads the gui
}