Jump to content

INIread into array of variables from dropdown


Recommended Posts

Hello,

I am trying to have Dropdown menu 1 (brands.ini) read from the contents of menu1.ini into an array of selections.

When selecting an option from menu1, dropdown menu2 (items.ini) will list specific contents accordingly.

For example,

----------------------

brands.ini

[Tools]

brand1

brand2

brand3

-----------------------

items.ini

[Brand]

item1=1

[Brand2]

item1=20

item2=40

 

Thank you in advance!

 

Link to comment
Share on other sites

Not quite sure if I'm following what you mean exactly but I think I understand what you're trying to do. Update a combobox with values based on the item selected? This might get you on the right track:

#include <GUIConstants.au3>

Global $aBrandsIni = ["Tools", "Items"]
Global $aTools = ["Tool 1", "Tool 2", "Tool 3"]
Global $aItems = ["Item 1", "Item 2", "Item 3"]

Global $hMain = GUICreate("Dropdown Menus", 240, 40)
Global $cboOne = GUICtrlCreateCombo("", 10, 10, 100, 20)
Global $cboTwo = GUICtrlCreateCombo("", 120, 10, 100, 20)

PopulateCombo($cboOne, $aBrandsIni)

GUISetState(@SW_SHOW)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0

        Case $cboOne
            ; Store the selected item
            Local $sSelection = GUICtrlRead($cboOne)

            ; Figure out which combobox value was selected
            If ($sSelection = "Tools") Then
                ; The "Tools" item was selected, update the second combo with the tools items
                PopulateCombo($cboTwo, $aTools)
            ElseIf ($sSelection = "Items") Then
                ; The "Items" item was selected, update the second combo with the items
                PopulateCombo($cboTwo, $aItems)
            EndIf
    EndSwitch
WEnd

Func PopulateCombo(Const ByRef $cboCombo, Const ByRef $aArray)
    Local $sItems = ""
    GUICtrlSetData($cboCombo, "")

    ; Creating the string used to set the data of the combobox: "Item 1|Item 2|Item 3|"
    For $i = 0 to UBound($aArray) - 1
        $sItems &= $aArray[$i] & "|"
    Next

    ; Update the combobox with the new items, remove the trailing '|'
    GUICtrlSetData($cboCombo, StringTrimRight($sItems, 1))
EndFunc

 

Link to comment
Share on other sites

On 6/3/2019 at 12:37 AM, InunoTaishou said:

Not quite sure if I'm following what you mean exactly but I think I understand what you're trying to do. Update a combobox with values based on the item selected? This might get you on the right track:

#include <GUIConstants.au3>

Global $aBrandsIni = ["Tools", "Items"]
Global $aTools = ["Tool 1", "Tool 2", "Tool 3"]
Global $aItems = ["Item 1", "Item 2", "Item 3"]

Global $hMain = GUICreate("Dropdown Menus", 240, 40)
Global $cboOne = GUICtrlCreateCombo("", 10, 10, 100, 20)
Global $cboTwo = GUICtrlCreateCombo("", 120, 10, 100, 20)

PopulateCombo($cboOne, $aBrandsIni)

GUISetState(@SW_SHOW)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0

        Case $cboOne
            ; Store the selected item
            Local $sSelection = GUICtrlRead($cboOne)

            ; Figure out which combobox value was selected
            If ($sSelection = "Tools") Then
                ; The "Tools" item was selected, update the second combo with the tools items
                PopulateCombo($cboTwo, $aTools)
            ElseIf ($sSelection = "Items") Then
                ; The "Items" item was selected, update the second combo with the items
                PopulateCombo($cboTwo, $aItems)
            EndIf
    EndSwitch
WEnd

Func PopulateCombo(Const ByRef $cboCombo, Const ByRef $aArray)
    Local $sItems = ""
    GUICtrlSetData($cboCombo, "")

    ; Creating the string used to set the data of the combobox: "Item 1|Item 2|Item 3|"
    For $i = 0 to UBound($aArray) - 1
        $sItems &= $aArray[$i] & "|"
    Next

    ; Update the combobox with the new items, remove the trailing '|'
    GUICtrlSetData($cboCombo, StringTrimRight($sItems, 1))
EndFunc

 

 

 

Hi!  Thanks for the reply and sorry for my late one.  Didn't get to work on the script till now.

Forgive me i explained the script im trying to create poorly.

Though this is a great start.

So i need the first dropdown to read and populate from the contents of an .ini

Then depending on which selection is made on the dropdown, the 2nd dropdown would read and populate from a section of another .ini

I hope this makes any sense haha.

Link to comment
Share on other sites

Slightly modified version of @InunoTaishou code:

;~ Test.ini
[Tools]
Tool_1 = Item1
Tool_2 = Item2
Tool_3 = Item3

[Item1]
Item1_1 = Item1 1
Item1_2 = Item1 2
Item1_3 = Item1 3

[Item2]
Item2_1 = Item2 1
Item2_2 = Item2 2
Item2_3 = Item2 3

[Item3]
Item3_1 = Item3 1
Item3_2 = Item3 2
Item3_3 = Item3 3

ComboBox Code

#include <Array.au3>
#include <GUIConstants.au3>

Global $sSelection, $sIniFilePath = @ScriptDir & "\Test.ini"
Global $aItems, $aTools = IniReadSection($sIniFilePath, "Tools")

Global $hMain = GUICreate("Dropdown Menus", 240, 40)
Global $cboOne = GUICtrlCreateCombo("", 10, 10, 100, 20)
    GUICtrlSetData($cboOne, _ArrayToString($aTools, "|", 1, -1, "|", 1, 1))
Global $cboTwo = GUICtrlCreateCombo("", 120, 10, 100, 20)

GUISetState(@SW_SHOW)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0

        Case $cboOne
            ; Store the selected item
            $sSelection = GUICtrlRead($cboOne)

            ; Figure out which combobox value was selected
            If $sSelection <> "" Then
                $aItems = IniReadSection($sIniFilePath, $sSelection)
                If @error Then ContinueLoop
                GUICtrlSetData($cboTwo, "")
                GUICtrlSetData($cboTwo, _ArrayToString($aItems, "|", 1, -1, "|", 1, 1))
            EndIf
    EndSwitch
WEnd

 

Link to comment
Share on other sites

On 6/10/2019 at 4:20 AM, Subz said:

Slightly modified version of @InunoTaishou code:

;~ Test.ini
[Tools]
Tool_1 = Item1
Tool_2 = Item2
Tool_3 = Item3

[Item1]
Item1_1 = Item1 1
Item1_2 = Item1 2
Item1_3 = Item1 3

[Item2]
Item2_1 = Item2 1
Item2_2 = Item2 2
Item2_3 = Item2 3

[Item3]
Item3_1 = Item3 1
Item3_2 = Item3 2
Item3_3 = Item3 3

ComboBox Code

#include <Array.au3>
#include <GUIConstants.au3>

Global $sSelection, $sIniFilePath = @ScriptDir & "\Test.ini"
Global $aItems, $aTools = IniReadSection($sIniFilePath, "Tools")

Global $hMain = GUICreate("Dropdown Menus", 240, 40)
Global $cboOne = GUICtrlCreateCombo("", 10, 10, 100, 20)
    GUICtrlSetData($cboOne, _ArrayToString($aTools, "|", 1, -1, "|", 1, 1))
Global $cboTwo = GUICtrlCreateCombo("", 120, 10, 100, 20)

GUISetState(@SW_SHOW)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0

        Case $cboOne
            ; Store the selected item
            $sSelection = GUICtrlRead($cboOne)

            ; Figure out which combobox value was selected
            If $sSelection <> "" Then
                $aItems = IniReadSection($sIniFilePath, $sSelection)
                If @error Then ContinueLoop
                GUICtrlSetData($cboTwo, "")
                GUICtrlSetData($cboTwo, _ArrayToString($aItems, "|", 1, -1, "|", 1, 1))
            EndIf
    EndSwitch
WEnd

 

This is exactly what i needed!!! Thank you so much :):):)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...