autohit

return variable index

4 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



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

1 person likes this

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

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.

Share this post


Link to post
Share on other sites

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

1 person likes this

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

  • Similar Content

    • 9252Survive
      By 9252Survive
      Hi All, 
       
      I am fairly new to AutoIT and I am still trying to learn, I have been using _FileListToArray to list all the files with a particular extension in an array and then loop through it for operation  (   For $i = 1 To UBound($FileArray) - 1).
      So far this has been working fine. But I am not able to figure out a problem that I have; what if I have 50 files but I only want to loop through first 10 files and then next ten and so on?  Or rather I should say, how I can I only feed max 10 files to the array at a time when I do _FileListToArray regardless of the total number of files in the folder?
      Any insight/help will be much appreciated 
    • NiftRex
      By NiftRex
      I'm trying to get an array from a website so that I can just get the url, but I am not sure how. I read a bit of arrays but I have a feeling I'd have to be writing a lot more than what I should be. I will include the script I have so far and the API url for what I want.
       
      API: https://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1 (I want the 'url' array that contains the url)
       
      Code:
      #include <MsgBoxConstants.au3> #include <Inet.au3> #include <Array.au3> $site = _INetGetSource('http://api.fast.com/netflix/speedtest?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=1') MsgBox($MB_SYSTEMMODAL, "Title", $site[1])  
    • rcmaehl
      By rcmaehl
      Alright, currently I'm trying to merge two loops:
       
      Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next  
      into one. Here's what I have so far:
       
      Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong.
       
      Thanks.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys  
       
    • TheAutomator
      By TheAutomator
      Hi people,
      It's been a while
      I have been scripting in vbscript for some time but now i'm back using AutoIt for a project:
      Scripting Adobe Illustrator with AutoIt .
      This vb code needs to be converted:
      Set appRef = CreateObject("Illustrator.Application") 'Create a new document and assign it to a variable Set documentRef = appRef.Documents.Add 'Create a new text frame item and assign it to a variable Set sampleText = documentRef.TextFrames.Add 'Set the contents and position of the TextFrame sampleText.Position = Array(200, 200) sampleText.Contents = "Hello World!" The ... = Array(200,200) part is done in one line in vb, is this possible in AutoIt without declaring an array first?
      I know I sound like a newbie but I never had to use arrays this way before..
      what i have:
      $appRef = ObjCreate("Illustrator.Application") ;Create a new document and assign it to a variable $documentRef = $appRef.Documents.Add ;Create a new text frame item and assign it to a variable $sampleText = $documentRef.TextFrames.Add ;Set the contents and position of the TextFrame ReDim $sampleText.Position[2] = [200, 200] <<<--- doesn't work... $sampleText.Contents = "Hello World!"