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.
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