ahk gui checkbox question Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

ahk gui checkbox question

27 Feb 2020, 03:17

hello bro


i have two question:

1 . how to simplify my code like if { ... if {....

2 .if i have a txt / ini file
how to loop create a checkbox from txt or ini file??

my text file maybe :
amd
yui
tert02
...




below is my script :

Code: Select all

Gui Add,Checkbox,vADMP01 x27 y83 w79h21,ADMP01
Gui Add,Checkbox,vETTP01 x27 y118 w79h19,ETTP01
Gui Add,CheckBox,vETTP02 x27 y150 w77h23,ETTP02
Gui Add,CheckBox,vETTP03 x27 y186 w79h21,ETTP03
Gui Add,CheckBox,vETTP04 x27 y221 w76h25,ETTP04


Gui Add,CheckBox,vJDNP01 x149 y80 w121h22,JDNP01
Gui Add,CheckBox,vJDNP02 x149 y119 w120h23,JDNP02
Gui Add,CheckBox,vJDNP03 x149 y161 w120h22,JDNP03
Gui Add,CheckBox,vJDNP04 x149 y199 w120h23,JDNP04


Gui Add,CheckBox,vKGRP01 x275 y80 w121 h22,KGRP01
Gui Add,CheckBox,vKGRP02 x275 y119 w120 h23,KGRP02
Gui Add,CheckBox,vKGRP04 x275 y162 w120 h23,KGRP04
Gui Add,CheckBox,vKGRP05 x275 y196 w120 h23,KGRP05


Gui Add,Button,x400 y300 w69 h23 default,OK

Gui Show,w500 h500,window
Return

ButtonCancel:
exitapp
return


;######################################################################################

ButtonOK:
Gui,submit,nohide

If(ADMP01=1){
	GoSub ADMP01
}

If(ETTP01=1){
	GoSub ETTP01
}


if(ADMP01=1){
	GoSub ADMP01
}


if(ETTP01=1){
	GoSub ETTP01
}


if(ETTP02=1){
	GoSub ETTP02
}

if(ETTP03=1){
	GoSub ETTP03
}

if(ETTP04=1){
	GoSub ETTP04
}

if(JDNP01=1){
	GoSub JDNP01
}

if(JDNP02=1){
	GoSub JDNP02
}

if(JDNP03=1){
	GoSub JDNP03
}

if(JDNP04=1){
	GoSub JDNP04
}

if(KGRP01=1){
	GoSub KGRP01
}

if(KGRP02=1){
	GoSub KGRP02
}

if(KGRP04=1){
	GoSub KGRP04
}

if(KGRP05=1){
	GoSub KGRP05
}


msgbox Done
return


;######################################################################################
ADMP01:
msgbox,iamADMP01
return



ETTP01:
msgbox,iamETTP01
return

ETTP02:
msgbox,iamETTP02
return

ETTP03:
msgbox,iamETTP03
return

ETTP04:
msgbox,iamETTP04
return


JDNP01:
msgbox,iamJDNP01
return


JDNP02:
msgbox,iamJDNP02
return

JDNP03:
msgbox,iamJDNP03
return


JDNP04:
msgbox,iamJDNP04
return

KGRP01:
msgbox,iamKGRP01
return


KGRP02:
msgbox,iamKGRP02
return


KGRP04:
msgbox,iamKGRP04
return


KGRP05:
msgbox,iamKGRP05
return
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: ahk gui checkbox question  Topic is solved

27 Feb 2020, 22:38

adrian_9832 wrote: 1 . how to simplify my code like if { ... if {....
You can put the labels in an array and reduce the if statements using a for loop like this:

Code: Select all

Subs := ["ADMP01", "ETTP01", "ETTP02", "ETTP03", "ETTP04", "JDNP01", "JDNP02", "JDNP03", "JDNP04", "KGRP01", "KGRP02", "KGRP04", "KGRP05"]

Gui Add,Checkbox,vADMP01 x27 y83 w79h21,ADMP01
Gui Add,Checkbox,vETTP01 x27 y118 w79h19,ETTP01
Gui Add,CheckBox,vETTP02 x27 y150 w77h23,ETTP02
Gui Add,CheckBox,vETTP03 x27 y186 w79h21,ETTP03
Gui Add,CheckBox,vETTP04 x27 y221 w76h25,ETTP04


Gui Add,CheckBox,vJDNP01 x149 y80 w121h22,JDNP01
Gui Add,CheckBox,vJDNP02 x149 y119 w120h23,JDNP02
Gui Add,CheckBox,vJDNP03 x149 y161 w120h22,JDNP03
Gui Add,CheckBox,vJDNP04 x149 y199 w120h23,JDNP04


Gui Add,CheckBox,vKGRP01 x275 y80 w121 h22,KGRP01
Gui Add,CheckBox,vKGRP02 x275 y119 w120 h23,KGRP02
Gui Add,CheckBox,vKGRP04 x275 y162 w120 h23,KGRP04
Gui Add,CheckBox,vKGRP05 x275 y196 w120 h23,KGRP05


Gui Add,Button,x400 y300 w69 h23 default,OK

Gui Show,w500 h500,window
Return

ButtonCancel:
exitapp
return


;######################################################################################

ButtonOK:
Gui,submit,nohide

for Each, Sub in Subs
	if(%Sub%=1){
		GoSub %Sub%
}
msgbox Done
return

;######################################################################################
ADMP01:
msgbox,iamADMP01
return



ETTP01:
msgbox,iamETTP01
return

ETTP02:
msgbox,iamETTP02
return

ETTP03:
msgbox,iamETTP03
return

ETTP04:
msgbox,iamETTP04
return


JDNP01:
msgbox,iamJDNP01
return


JDNP02:
msgbox,iamJDNP02
return

JDNP03:
msgbox,iamJDNP03
return


JDNP04:
msgbox,iamJDNP04
return

KGRP01:
msgbox,iamKGRP01
return


KGRP02:
msgbox,iamKGRP02
return


KGRP04:
msgbox,iamKGRP04
return


KGRP05:
msgbox,iamKGRP05
return


adrian_9832 wrote: 2 .if i have a txt / ini file
how to loop create a checkbox from txt or ini file??

my text file maybe :
amd
yui
tert02
...
Here's an example:

Code: Select all

; replace the following with: FileRead, FileText
FileText =
(
amd
yui
tert02
)

loop, Parse, FileText, `n, `r
Gui, Add, CheckBox, % "x27 y" (36 * A_Index) " v" A_LoopField, % A_LoopField
Gui, Show, w150 h150
return
adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

Re: ahk gui checkbox question

29 Feb 2020, 00:27

That was impressive. You kick ass
thanks for your help
adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

Re: ahk gui checkbox question

29 Feb 2020, 00:45

Inspired by you i improve below code

Code: Select all

NumX := 80
NumY := 50
ex := "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,3637,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73"
Loop, parse, ex, `,
{
	Gui Add,Checkbox, x%NumX% y%NumY% w60 h20  v%A_LoopField% , %A_LoopField%
	NumY := NumY + 40
	if (NumY == "610"){
		NumY := 50
		NumX := NumX + 80
	}
}



Gui Add,Button,x405 y611 w69 h23 default,OK
Gui Add,Button,x300 y611 w69 h23 default,Check All

Gui Show,w942 h661,Windows
Return
[Mod edit: [code][/code] tags added]
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: ahk gui checkbox question

29 Feb 2020, 05:39

Very nice. You don’t need a list of numbers if you’re simplifying it to that. You can use a simple loop and the A_Index variable. But perhaps those numbers were just placeholders for other labels. If you do stick with numbers, you could do this:

Code: Select all

NumX := 80
NumY := 50
Loop, 73
{
	Gui Add,Checkbox, x%NumX% y%NumY% w60 h20  v%A_Index% , %A_Index%
	NumY := NumY + 40
	if (NumY == "610"){
		NumY := 50
		NumX := NumX + 80
	}
}



Gui Add,Button,x405 y611 w69 h23 default,OK
Gui Add,Button,x300 y611 w69 h23 default,Check All

Gui Show,w942 h661,Windows
Return
By the way, there is a typo in your number list where you have “3637” instead of “36,37”.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: MrDoge, peter_ahk and 347 guests