Jump to content

Recommended Posts

Posted (edited)

Hi guys,

I am a fairly new poster and is probably over thinking this. I have 4 arrays, 3 input box and and 1 combo box. The first array is read into the list of the combo box. 

When the first item in combo box 1 is selected, each of the 3 text box is populated accordingly with the value from index 1 of the different arrays. When the second item in the combo box is selected, it will populate the text boxes with index 2 of the arrays. My question is, how can I do this without hardcoding in the array index number? I have thought about setting a variable to "indexof" array but I was not able to find such thing on autoit.

Case $combo_box
    if GUICtrlRead($combo_box) = $array1[0] Then
        GUICtrlSetData($inputbox1,$array2[0])
        GUICtrlSetData($inputbox2,$array3[0])
        GUICtrlSetData($inputbox3,$array4[0])


    ElseIf  GUICtrlRead($combo_box) = $array1[1] Then
        GUICtrlSetData($inputbox1,$array2[1])
        GUICtrlSetData($inputbox2,$array3[1])
        GUICtrlSetData($inputbox3,$array4[1])
    Else
        GUICtrlSetData($inputbox1,$array2[2])
        GUICtrlSetData($inputbox2,$array3[2])
        GUICtrlSetData($inputbox3,$array4[2])
EndIf

 

Edited by autohit
  • Moderators
Posted

autohit,

Welcome to the AutoIt forums.

I would just search the first array for a match like this:

#include <GUIConstantsEx.au3>
#include <Array.au3>

Global $array1[] = ["A1", "B1", "C1"]
Global $array2[] = ["A2", "B2", "C2"]
Global $array3[] = ["A3", "B3", "C3"]
Global $array4[] = ["A4", "B4", "C4"]

$hGUI = GUICreate("Test", 500, 500)

$combo_box = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($combo_box, _ArrayToString($array1))

$inputbox1 = GUICtrlCreateInput("", 10, 200, 200, 20)
$inputbox2 = GUICtrlCreateInput("", 10, 250, 200, 20)
$inputbox3 = GUICtrlCreateInput("", 10, 300, 200, 20)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $combo_box
            $iIndex = _ArraySearch($array1, GUICtrlRead($combo_box))
            GUICtrlSetData($inputbox1, $array2[$iIndex])
            GUICtrlSetData($inputbox2, $array3[$iIndex])
            GUICtrlSetData($inputbox3, $array4[$iIndex])
    EndSwitch

WEnd

Please ask if you have any questions.


M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted

thank you so much Melba23. This works but let me see if I understand this correctly.

Whenever the $combo_box is clicked (triggered in an event), _ArraySearch searches for the string selected and return it's state (int). In this case, the state is an index which is use to populate the other text boxes? Let me know if I'm understanding this wrong.

  • Moderators
Posted

autohit,

_ArraySearch searches in the array you use to populate the combo and returns the index of the string found - that index is then used to populate the inputs from their arrays because you have the indexes linked.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

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
×
×
  • Create New...