Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Is there way how to make this code shorter?


  • Please log in to reply
7 replies to this topic
BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012
 
For the case that I would like add many listbox in gui, at least 20. When the listbox changes, it should change next listbox. So here I have changelist_%n% ... Is there any way how to tell AHK, that there can be any number of this labels?
createList(n,ypos){

gui, 4:Add,DropDownList,x361 y%ypos% w95 vclasses_%n% gchangelist_%n%, "a|b|c"
}
 
changelist_20:
changelist_19:
changelist_18:
changelist_17:
changelist_16:
changelist_15:
changelist_14:
changelist_13:
changelist_12:
changelist_11:
changelist_10:
changelist_9:
changelist_8:
changelist_7:
changelist_6:
changelist_5:
changelist_4:
changelist_3:
changelist_2:
changelist_1:
  msgBox
return

 



BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

Is there way how to make this shorter?



hd0202
  • Members
  • 709 posts
  • Last active: Feb 14 2016 08:05 PM
  • Joined: 13 Aug 2006

Yes, see my example:

loop, 4
{
n := a_index
gui, Add,DropDownList,x361 y%ypos% w95 vclasses_%n% gchangelist, a|b|c
}
gui, show
return

changelist:
gui, submit, nohide
stringsplit, c, a_guicontrol, _
msgbox, % a_guicontrol " : " classes_%c2%
return

You use only one g_variable and decide in this subroutine what to do depending on the number of the v_variable.

 

Hubert



BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

Cool. Did not think about it. Thanks

 

Let me have yet one more question

 

Why this command, does not change my dropDownList?

GuiControl, 4:, unit_%no%,<Search for unit?>

I want to change the list in unit_1 control (the control is created in my gui):

gui, 4:Add,DropDownList,x505 y%ypos% w125 vunit_%n%,<Search in class>||


hd0202
  • Members
  • 709 posts
  • Last active: Feb 14 2016 08:05 PM
  • Joined: 13 Aug 2006

what is your variable for numbering the units? n or no shocked.png

Hubert



BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

In both cases n and no is equal to 1. So the control to be changed is unit_1. The gui is created within function, but guicontrol is in soubroutine.



hd0202
  • Members
  • 709 posts
  • Last active: Feb 14 2016 08:05 PM
  • Joined: 13 Aug 2006

In my test it is added as second option in the dropdownlist.

To replace it I changed your code to

GuiControl, 4:, unit_%no%,|
GuiControl, 4:, unit_%no%,<Search for unit?>

Hubert



BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

Here once again:

gui, 4:Add,DropDownList,w125 vclass_1 gchangelist,<Select class>||Buildings|Units|
gui, 4:Add,DropDownList,w125 vunit_1,|<Search in class>||
gui, 4:show

changelist:
GuiControl, 4:, unit_1,<Search for unit?>  
return

done


Edited by BrandonHotkey, 07 May 2013 - 06:05 PM.
fixed code tags