GUI control issue - missing something ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

GUI control issue - missing something ?

19 Jun 2021, 08:05

Hi all, here's an (almost) working script that can be launched. :) You can download it here with a pre-built folder hierarchy, it will be much easier to understand : https://we.tl/t-U3e1kJqOzE

Launching the script creates a GUI with a number of comboboxes that allows the user to select up to 10 devices.
A device is made of a type + a brand + a model.

To find all possible devices, a folder hierarchy is used, selecting only folder names, not file names.
The folder hierarchy is as follows : "type" folders \ "brand" folders within any "type" folder \ "model" folders within any "brand" folder.
A working LoadFolders() function creates a list of all the folders within a given root folder (not recursively, which is intended).

To select a device, the user first selects a type from a combobox.
Once the type is selected, the next combobox updates with all the models matching the selected type.
So for example in the pre-built hierarchy, if we select type "T2", the next combobox updates with models "M3" and "M4" which are the folders within the "T2" folder.
That is the part that's not working yet. :eh:

In the ChooseType subroutine, I first create an Index variable to determine which row was selected. That works.
In the next line, I try to use the Type%Index% variable, which is the variable associated to the corresponding control, so it should normally be the result of the selected control.
Unfortunately, Type%Index% is always empty, no matter what I do.
As a consequence, the models combobox information isn't correct.
What am I missing here ? Thanks in advance to all willing to help. :)

Code: Select all

#NoEnv
#SingleInstance, Force
SendMode Input
SetWorkingDir, % A_ScriptDir

global MaxDevices := 10
PresetsPath       := A_ScriptDir

global TypeList   := ""
global FolderList := ""
global Brands     := ""
global Models     := ""
Loop, %MaxDevices%
{
  Type%A_Index%      := ""
  Brand%A_Index%     := ""
  Model%A_Index%     := ""
  BrandList%A_Index% := ""
  ModelList%A_Index% := ""
}

LoadFolders(PresetsPath)
TypeList := FolderList
StringReplace, TypeList, TypeList, |TEMPLATES,
CreateGui()
return

; -----------------------------------------------------------

LoadFolders(RootFolder)
{
  FolderList    := ""
  objWShell     := ComObjCreate("WScript.Shell")
  objFSO        := ComObjCreate("Scripting.FileSystemObject")
  objFolder     := objFSO.GetFolder(RootFolder)
  objSubFolders := objFolder.SubFolders 

  For folder in objSubFolders
    FolderList .= Folder.name "|"
  return
}

; -----------------------------------------------------------

CreateGui()
{
  Gui, Font, s24, Calibri
  Gui, Add, Text, x210 y10 Center, Type
  Gui, Add, Text, x580 y10 Center, Brand
  Gui, Add, Text, x950 y10 Center, Model
  Loop, %MaxDevices%
  {
    y := A_Index * 60 + 20
    Gui, Add, Text, x10 y%y%, %A_Index% 
    Gui, Add, ComboBox, x60 y%y% vType%A_Index%  gChooseType , %TypeList%
    Gui, Add, ComboBox, x+20     vBrand%A_Index% gChooseBrand, % BrandList%A_Index%
    Gui, Add, ComboBox, x+20     vModel%A_Index% gChooseModel, % ModelList%A_Index%
  }
  Gui, Add, Button, Default x600 y+60 w200, Cancel
  Gui, Add, Button, Default x+20 w200, Save
  Gui, Show
  return
}

; -----------------------------------------------------------

ChooseType:
  StringReplace, Index, A_GuiControl, Type, ,
  Root := PresetsPath "\" Type%Index%
  LoadFolders(Root)
  BrandList%Index% := FolderList
  GuiControl,, Brand%Index%, % "|" BrandList%Index%
return

ChooseBrand:
  StringReplace, Index, A_GuiControl, Brand, ,
  Root := PresetsPath "\" Type%Index% "\" Brand%Index%
  LoadFolders(Root)
  ModelList%Index% := FolderList
  GuiControl,, Model%Index%, % "|" ModelList%Index%
return

ChooseModel:
  StringReplace, Index, A_GuiControl, Model, ,
return

; -------------------------------------------

ButtonCancel:
  ExitApp

ButtonSave:
  ; Save Brand1 to Brand10 into Devices.ini
  ; Save Device1 to Device10 into Devices.ini
return
just me
Posts: 9457
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI control issue - missing something ?  Topic is solved

19 Jun 2021, 08:19

To read the selected values into the control variable add

Code: Select all

Gui, Submit, NoHide
at the top of the labels.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI control issue - missing something ?

19 Jun 2021, 16:55

Thanks @just me ! I knew I was missing something, and it was exactly that ! :D Works perfectly now.

Maybe one more question : since I have Comboboxes, I can type a text in them. Is there a way to adjust the displayed lists dynamically ?
For example, let's say a list has the following items : Red, Blue, Green, Yellow, Brown. If I type "B", I'd like only the "Blue" and "Brown" items to remain in the list.

Even better, If I type "Bl", then only "Blue" would remain. And since it's the only remaining item, I'd like it to be automatically selected. Well, that would be easy since I would only need to add a "||" after it.

Would that be easy to achieve ?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, jaka1, mikeyww and 335 guests