Jump to content

GUI combobox should fill data in list


Daemante2018
 Share

Recommended Posts

The code below has a button (Go!) which, depending on the choice made in the combobox, is meant to retrieve the data from the corresponding TXT file. It does work for "Option1", but, not "Option2". What am I doing wrong in the case section?

 

#include <Array.au3>
#include <File.au3>
#include <GUIConstants.au3>
#include <GuiListBox.au3>
#include <ListBoxConstants.au3>

$TestGUI = GUICreate("", 343, 611, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xFFFFFF)
$SELECTOPTION = GUICtrlCreateCombo("Select Option", 8, 16, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Option1|Option2")
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$OPTIONLIST = GUICtrlCreateList("", 8, 64, 325, 524, BitOR($LBS_NOSEL, $WS_VSCROLL))
$FILLOPTIONDATA = GUICtrlCreateButton("Go!", 248, 32, 75, 25)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FILLOPTIONDATA
            Select
                Case GUICtrlRead($SELECTOPTION)
                    If GUICtrlRead($SELECTOPTION) = "Option1" Then
                        GUICtrlSetData($OPTIONLIST, "")
                        _CallOption1()
                    EndIf
                Case GUICtrlRead($SELECTOPTION)
                    If GUICtrlRead($SELECTOPTION) = "Option2" Then
                        GUICtrlSetData($OPTIONLIST, "")
                        _CallOption2()
                    EndIf
            EndSelect
    EndSwitch
WEnd

Func _CallOption1()
    Local $aFileList
    _FileReadToArray("option1.txt", $aFileList)
    For $i = 1 To $aFileList[0]
        _GUICtrlListBox_AddString($OPTIONLIST, $aFileList[$i])

    Next
EndFunc   ;==>_CallOption1

Func _CallOption2()
    Local $aFileList
    _FileReadToArray("option2.txt", $aFileList)
    For $i = 1 To $aFileList[0]
        _GUICtrlListBox_AddString($OPTIONLIST, $aFileList[$i])

    Next
EndFunc   ;==>_CallOption2

 

option2.txt

option1.txt

TestCombo.au3

Edited by Daemante2018
Link to comment
Share on other sites

The CASE clauses of the SELECT statement expect an expression that evaluates to a boolean value.  You were close.  I think the snippet below should help you move forward. 

The SELECT statement and the SWITCH statement are similar but their CASE clauses expect different values.  You appeared to have been trying to use the SELECT as if it was a SWITCH statement.  The HELP file is you friend. ;)  Pay more attention to the examples in the HELP file.

https://www.autoitscript.com/autoit3/docs/keywords/Select.htm

 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FILLOPTIONDATA
            Select
                Case GUICtrlRead($SELECTOPTION) = "Option1"
                    GUICtrlSetData($OPTIONLIST, "")
                    _CallOption1()
                Case GUICtrlRead($SELECTOPTION) = "Option2"
                    GUICtrlSetData($OPTIONLIST, "")
                    _CallOption2()
            EndSelect
    EndSwitch
WEnd

 

Edited by TheXman
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...