Page 1 of 1

How to check which checkboxes are checked (Multiple checkboxes)

Posted: 03 May 2024, 22:21
by jollyjoe
I want to append each checkbox control name to a text file, this is what the gui looks like:
image.png
image.png (3.29 KiB) Viewed 371 times
Each checkbox is named mob1, mob2, mob3, ... and they all point to 1 gLabel called mobmenu

Heres my current code for the glabel, i tried using a variable for ControlGet but it doesnt work

Code: Select all

mobmenu:
	Gui, Submit, NoHide
	_count = 0
	Loop {
		_count++
		_mob := "mob" . _count
		if (_count < 22) {
			ControlGet, isChecked, Checked,, %_mob%
			msgbox % _mob " = " isChecked " count is " _count ;isChecked is always blank, %_mob% is not getting read in the line above
			if (isChecked = 1) {
				FileAppend, %_mob%, CMAP.txt
			}
		}
	}
return
How do I make it so that every box that is checked gets appended to a txt file?

Re: How to check which checkboxes are checked (Multiple checkboxes)

Posted: 04 May 2024, 06:21
by mikeyww
Hello,

An If statement inside an infinite loop gets you an infinite loop, unless you provide an iteration count, Until, or break from the loop in some way (e.g., Break).

How to iterate a finite loop and get the iteration number

Below is a simple approach that will store all of your values instead of creating an ever-expanding text file.

Code: Select all

#Requires AutoHotkey v1.1.33.11
Gui Font, s10
Gui Add, CheckBox, w250 vmob1 gMobmenu, Mob1
Gui Add, CheckBox, wp   vmob2 gMobmenu, Mob2
Gui Show,, Checkboxes
Return

Mobmenu:
Gui Submit, NoHide
IniWrite % %A_GuiControl%, config.ini, Checkboxes, % A_GuiControl
Return

When you submit the GUI, you have all of its associated variables' values, so ControlGet is not needed.

Code: Select all

Mobmenu:
Gui Submit, NoHide
Loop 2 {
 _mob := "mob" A_Index
 MsgBox % %_mob%
}
Return