bscarano Posted June 13, 2016 Posted June 13, 2016 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 expandcollapse popup#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
Moderators Melba23 Posted June 13, 2016 Moderators Posted June 13, 2016 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
bscarano Posted June 13, 2016 Author Posted June 13, 2016 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.
Moderators Melba23 Posted June 13, 2016 Moderators Posted June 13, 2016 bscarano, Easy: expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now