Checkboxes Editing ini File Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Teutonic84
Posts: 4
Joined: 25 Feb 2019, 11:32

Checkboxes Editing ini File  Topic is solved

25 Feb 2019, 12:02

So I'm trying to create a script that opens up a GUI and has multiple tabs with checkboxes that edit an ini file. In the first tab, the checkboxes are auto-populated from the ini file "general_settings.ini". In the ini file if the option=enabled then the checkbox is enabled when you open the script. If it's disabled then it's unchecked. I have it do this all automatically without me manually specifying the variables, so then if i add any options i won't have to keep adding them manually in the script. Problem is I can't figure out how to get the checkboxes to then edit the ini file based off of if they are checked or unchecked. If the option is unchecked i want it to then edit that option in the ini file and set it to "disabled". i was able to get it working fine when i manually specified the variables on my own, but i can't figure out how to do it with the auto-variable method. I believe the issue lies within the loop. The "gsave" portion doesn't get recognized when it's in the loop, but if i manually specify it outside the loop it works fine.

I'm pretty new to autohotkey so please explain things like you would a newbie. Thank you for your time.

EDIT: I was able to figure it out! I have revised my script below. It uses two other scripts that are included as classes that someone else made. If anyone would like to try out my script i can attach the classes and explain how the script works.

Here is my script file:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
#Include Class_ScrollGUI.ahk
#Include Class_INI.ahk
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetBatchLines, -1

; ----------------------------------------------------------------------------------------------------------------------
; Main Window GUI
Gui, New, +hwndHGUI +Resize
Gui, Margin, 2, 4
I := 0
inifile = general_settings.ini
INI_Init("general_settings.ini")
Gui, Add, Tab,, General|Import Options|Paths
Loop, %inisections%
{
  FoundSection := A_index
  section := Section%A_index%
  numberOfKeys%A_index% := Section%A_index%_keys
  loop, % numberOfKeys%A_index%
  {
    IniRead, %section%_val%A_index%, %inifile%, %section%, % Section%FoundSection%_key%A_index%, %A_Space%
    value := %section%_val%A_index%
    option := Section%FoundSection%_key%A_index%
    ;ListVars
    ;Msgbox, value=%value% option=%option%
    IF value=enabled
    {
      Gui, Add, Checkbox, v%section%_checkbox%A_index% gSave Checked, % Section%FoundSection%_key%A_index%
    }
    ELSE IF value=disabled
    {
      Gui, Add, Checkbox, v%section%_checkbox%A_index% gSave, % Section%FoundSection%_key%A_index%
    }
  }
}

inifile = import_options.ini
INI_Init("import_options.ini")
Gui, Tab, Import Options
Loop, %inisections%
{
  FoundSection := A_index
  section := Section%A_index%
  numberOfKeys%A_index% := Section%A_index%_keys
  loop, % numberOfKeys%A_index%
  {
    IniRead, val%A_index%, %inifile%, %section%, % Section%FoundSection%_key%A_index%, %A_Space%
    value := val%A_index%
    option := Section%FoundSection%_key%A_index%
    ;ListVars
    ;Msgbox, value=%value% option=%option%
    IF value=enabled
    {
      Gui, Add, Checkbox, v%section%_checkbox%A_index% gSave2 Checked, % Section%FoundSection%_key%A_index%
    }
    ELSE IF value=disabled
    {
      Gui, Add, Checkbox, v%section%_checkbox%A_index% gSave2, % Section%FoundSection%_key%A_index%
    }
  }
}

Gui, Tab, Paths
Gui, Add, Checkbox, vpath1, Test Path 1
Gui, Add, Checkbox, vpath2, Test Path 2

; Create ScrollGUI1 with both horizontal and vertical scrollbars and scrolling by mouse wheel
Global SG1 := New ScrollGUI(HGUI, 300, 200, "+Resize +LabelGui1", 3, 4)
; Show ScrollGUI1
SG1.Show("ScrollGUI1", "y0 xcenter")
Gui, Show
return

Save:
Gui, Submit, NoHide
inifile = general_settings.ini
INI_Init("general_settings.ini")
Loop, %inisections%
{
  FoundSection := A_index
  section := Section%A_index%
  numberOfKeys%A_index% := Section%A_index%_keys
  loop, % numberOfKeys%A_index%
  {
    IniRead, %section%_val%A_index%, %inifile%, %section%, % Section%FoundSection%_key%A_index%, %A_Space%
    value := %section%_val%A_index%
    option := Section%FoundSection%_key%A_index%
    IfEqual, %section%_checkbox%A_index%, 1, IniWrite, enabled, %inifile%, %section%, %option%
    IfEqual, %section%_checkbox%A_index%, 0, IniWrite, disabled, %inifile%, %section%, %option%
  }
}
return
;Msgbox, option=%option% value=%value% section=%section% inifile=%inifile%
;Msgbox, rom_renamer = %rom_renamer%`nlaunch_steamconsole_on_startup = %launch_steamconsole_on_startup%


Save2:
Gui, Submit, NoHide
inifile = import_options.ini
INI_Init("import_options.ini")
Loop, %inisections%
{
  FoundSection := A_index
  section := Section%A_index%
  numberOfKeys%A_index% := Section%A_index%_keys
  loop, % numberOfKeys%A_index%
  {
    IniRead, %section%_val%A_index%, %inifile%, %section%, % Section%FoundSection%_key%A_index%, %A_Space%
    value := %section%_val%A_index%
    option := Section%FoundSection%_key%A_index%
    IfEqual, %section%_checkbox%A_index%, 1, IniWrite, enabled, %inifile%, %section%, %option%
    IfEqual, %section%_checkbox%A_index%, 0, IniWrite, disabled, %inifile%, %section%, %option%
  }
}
return

;=======
;hotkeys
;=======
ESC::
ExitApp

Gui1Close:
Gui1Escape:
ExitApp

Gui1Size:
Return

Gui2Size:
Return

Gui2Close:
Gui2Escape:
   SG2 := ""
Return
and here is the "general_settings.ini" file:

Code: Select all

[General]
Option1=disabled
Option2=enabled
dammtools
Posts: 12
Joined: 11 Oct 2015, 18:02

Re: Checkboxes Editing ini File

04 Nov 2019, 08:31

Teutonic84 wrote:
25 Feb 2019, 12:02
...It uses two other scripts that are included as classes that someone else made. If anyone would like to try out my script i can attach the classes and explain how the script works.
Seems useful to me. Can you attach the classes and explain this, please?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, peter_ahk, Spawnova and 347 guests