Jump to content
bscarano

Updating Label when combobox selection changes

Recommended Posts

bscarano

Greetings,

I have searched and tried to figure out how, when  a user selects a name from a combobox, it will update a location (as well as BU code) on a GUI form.

 

I cannot figure out how to update the label 2 and label 3 with the correct information

Basically, if user chooses Smith, Joshua, Label 2 would equal Chicago (Shaumburg) and Label 3 would equal WDL

Any help is greatly appreciated.

 

Brendon

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

; AutoIt Version 3.0.103
; Language:       English
; Author:         Larry Bailey
; Email:          psichosis@tvn.net
; Date: January 11, 2005
;
; Script Function
; Creates a simple GUI showing the use of
; a label, a combobox and a button
; Selecting an item from the combobox
; and clicking the button updates the label text

Local $TechnicianARR[6][3] = [["SMITH, JOSHUA","CHICAGO (SCHAUMBURG)","WDL"],["OVERTON, MAX M","CAMBRIDGE MA","QCA"],["RICHARDSON, CHARLIE M","TETERBORO","TBR"],["ALEXANDER, FELIX","ST. LOUIS (LAB)","STL"],["ALVESON, RONALD","TETERBORO","QTE"],["ANDERSON, BILL","ATLANTA","SKB"]]

_Main()

Func _Main()
    Local $Label_1, $Combo_2, $Label_2, $Label_3, $TechNameVar, $TechName, $TechLocVar, $TechBUVar, $button1, $msg, $data

    ; Create the GUI window and controls
    GUICreate("MyGUI", 250, 157, (@DesktopWidth - 191) / 2, (@DesktopHeight - 157) / 2)
    $Label_1 = GUICtrlCreateLabel("Label1", 30, 40, 200, 21, 0x1000)
    $Label_2 = GUICtrlCreateLabel("Label2", 30, 60, 200, 21, 0x1000)
    $Label_3 = GUICtrlCreateLabel("Label3", 30, 80, 200, 21, 0x1000)

    $Combo_2 = GUICtrlCreateCombo("", 30, 100, 200, 21)
            For $i = 0 to UBound($TechnicianARR,1)-1
                Local $TechNameVar = $TechnicianARR[$i][0]
                GUICtrlSetData($Combo_2, $TechNameVar)
            Next
    $button1 = GUICtrlCreateButton("Set Label", 30, 130, 150, 20)

    ; Run the GUI until it is closedsingle user                                     cp-uncategorized
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
                ;When button is pressed, label text is changed
                ;to combobox value
            Case $msg = $button1
                $TechName = GUICtrlRead($Combo_2)
            For $i = 0 to UBound($TechnicianARR,1)-1
                    For $j = 0 to UBound($TechnicianARR,2)-1
                Local $TechLocVar = $TechnicianARR[0][$j]
                    For $k = 0 to UBound($TechnicianARR,3)-1
                        Local $TechBUVar = $TechnicianARR[0][$k]
                        ;msgbox($mb_ok,"Tech Info", "Name: " & $TechnicianARR[$i][$j][$k])
                    Next
                Next
            Next
                GUICtrlSetData($Label_1, $TechName)
                GUICtrlSetData($Label_2, $TechLocVar)
                GUICtrlSetData($Label_3, $TechBUVar)
        EndSelect
    WEnd
    Exit

EndFunc   ;==>_Main

 

Share this post


Link to post
Share on other sites
Melba23

bscarano,

Welcome to the AutoIt forums.

You were overcomplicating matters just a little bit:

Case $msg = $button1
    $TechName = GUICtrlRead($Combo_2)
    For $i = 0 To UBound($TechnicianARR, 1) - 1
        ; Look for the tech name
        If $TechName = $TechnicianARR[$i][0] Then
            ; if found then fill the labels
            GUICtrlSetData($Label_1, $TechName)
            GUICtrlSetData($Label_2, $TechnicianARR[$i][1])
            GUICtrlSetData($Label_3, $TechnicianARR[$i][2])
            ; No point in looking further
            ExitLoop
        EndIf
    Next

Please ask if you have any questions.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
bscarano

That worked perfectly!

 

Thank you so much!

Share this post


Link to post
Share on other sites
bscarano

One more question, is there a way to get this to update when the combobox is changed?

 

I tried using a case statement, but it keeps reverting back to the last item in the Array.

Share this post


Link to post
Share on other sites
Melba23

bscarano,

Easy:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $TechnicianARR[6][3] = [["SMITH, JOSHUA", "CHICAGO (SCHAUMBURG)", "WDL"], ["OVERTON, MAX M", "CAMBRIDGE MA", "QCA"], ["RICHARDSON, CHARLIE M", "TETERBORO", "TBR"], ["ALEXANDER, FELIX", "ST. LOUIS (LAB)", "STL"], ["ALVESON, RONALD", "TETERBORO", "QTE"], ["ANDERSON, BILL", "ATLANTA", "SKB"]]

_Main()

Func _Main()
    Local $Label_1, $Combo_2, $Label_2, $Label_3, $TechNameVar, $TechName, $TechLocVar, $TechBUVar, $button1, $msg, $data

    ; Create the GUI window and controls
    GUICreate("MyGUI", 250, 157, (@DesktopWidth - 191) / 2, (@DesktopHeight - 157) / 2)
    $Label_1 = GUICtrlCreateLabel("Label1", 30, 40, 200, 21, 0x1000)
    $Label_2 = GUICtrlCreateLabel("Label2", 30, 60, 200, 21, 0x1000)
    $Label_3 = GUICtrlCreateLabel("Label3", 30, 80, 200, 21, 0x1000)

    $Combo_2 = GUICtrlCreateCombo("", 30, 100, 200, 21)
    For $i = 0 To UBound($TechnicianARR, 1) - 1
        Local $TechNameVar = $TechnicianARR[$i][0]
        GUICtrlSetData($Combo_2, $TechNameVar)
    Next
    
    ; Run the GUI until it is closedsingle user                                     cp-uncategorized
    GUISetState()

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Combo_2 ; Combo is actioned <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                $TechName = GUICtrlRead($Combo_2)
                For $i = 0 To UBound($TechnicianARR, 1) - 1
                    ; Look for the tech name
                    If $TechName = $TechnicianARR[$i][0] Then
                        ; if found then fill the labels
                        GUICtrlSetData($Label_1, $TechName)
                        GUICtrlSetData($Label_2, $TechnicianARR[$i][1])
                        GUICtrlSetData($Label_3, $TechnicianARR[$i][2])
                        ; No point in looking further
                        ExitLoop
                    EndIf
                Next
        EndSelect
    WEnd
    Exit

EndFunc   ;==>_Main

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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

×