Code: Select all
#SingleInstance, Force
Global h11Text, h12Text, h21Text, h22Text := ""
Global v1, v2, v3, v4 := ""
Global whereAmI := 0
Global stringToSave := ""
Global StringArray := []
Global selectedFile := ""
Global loadedFile := False
main()
main(){
showgui1() ; show the gui without the save function
}
ShowGui1(){
global
WhereAmI := 1
Gui 1:Destroy
Gui 1:Default
Gui Add, Edit, r5 vh11Text,
Gui Add, Edit, r5 vh12Text,
Gui Add, Button, gGoTo2, Next
Gui Add, Button, gLoad, Load
Gui Add, Button, gSaveToFile, Save
Gui Add, Button, gQuit, Quit
Gui, 1:Show, w400 h400, Gui 1
loadfields()
return
}
ShowGui2(){
global
WhereAmI := 2
Gui 2:Destroy
Gui 2:Default
Gui Add, Edit, r2 vh21Text,
Gui Add, Edit, r2 vh22Text,
Gui Add, Button, gGoTo1, Next
Gui Add, Button, gSaveToFile, Save
Gui Add, Button, gQuit, Quit
Gui, 2:Show, w400 h400 Center, Gui 2
loadfields()
return
}
Load(){
Global
FileSelectFile, selectedFile
FileRead, fileData, %selectedFile%
If (selectedFile != "") { ; if a file has been selected
LoadedFile := True ; we have loaded the file
}
StringArray:= StrSplit(fileData, "|") ;split the file using the | separator
v1 := StringArray[1]
v2 := StringArray[2]
v3 := StringArray[3]
v4 := StringArray[4]
loadfields()
return
}
Goto1(){
SaveData()
Gui 2:Destroy
ShowGui1()
return
}
Goto2(){
SaveData()
Gui 1:Destroy
ShowGui2()
return
}
LoadFields(){
Global
if (whereAmI = 1) {
GuiControl, 1:, h11Text, % v1
GuiControl, 1:, h12Text, % v2
}
Else if (whereAmI = 2) {
GuiControl, 2:, h21Text, % v3
GuiControl, 2:, h22Text, % v4
}
return
}
Quit(){
ExitApp
}
SaveData(){
Global
if (whereAmI = 1){
GuiControlGet v1,,h11Text
GuiControlGet v2,,h12Text
}
Else {
GuiControlGet v3,,h21Text
GuiControlGet v4,,h22Text
}
return
}
SavetoFile(){
StringToSave := ""
StringToSave := v1 "|" v2 "|" v3 "|" v4
FileDelete %A_ScriptDir%\test.txt
FileAppend, %StringToSave%, %A_ScriptDir%\test.txt
return
}
#z::ExitApp
Invariably I had to have the documentation page open for almost everything I did. I am a newbie to ahk, however I felt that the inconsistencies I found would have me working this way for some time. As I use ahk for hobby programming and a little for 'real' work, I would like to know if my issues are genuine or borne out of ignorance of the language. If they are real issues, does V2 fix all or any of those? Thanks for reading.