Sign in to follow this  
Followers 0
waardd

multidimensional array use in an dropdownlist

5 posts in this topic

I'm fairly new at this and im googling like crazy...

On this forum i found a script to cionvert a ini file to a array ()

I used that script to read my own file and that works... but....

I want to use it in my dropdownlist and then the array is empty??? What am i doing wrong?

; connect to server script v0.1
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
;Functions
Func win($TITLE, $TEXT)
    IF WinExists($TITLE, $TEXT) Then
        IF NOT WinActive($TITLE, $TEXT) Then
        WinActivate($TITLE, $TEXT)
        EndIf
    EndIf
EndFunc
Func _populateARRAY()
    ; Get the entries
    Local $srvREAD = IniReadSection("c:\home\srvlist.ini", "SERVERLIJST")
    ; Size the Global array correctly
    Global $ASservers[$srvREAD[0][0] + 1][5]
    ; Declare this Local array outside the loop
    Local $srvREAD2
    For $i = 1 To $srvREAD[0][0]
        ; Split the delimited string into an array
        $srvREAD2 = StringSplit($srvREAD[$i][1], "|")
        ; Now add the elements to the Global array
        For $j = 1 To $srvREAD2[0]
            $ASservers[$i][$j] = $srvREAD2[$j]
        Next
    Next
EndFunc   ;==>_populateARRAY
; Declare the array as Global
Global $ASservers
; Fill the array
_populateARRAY()
; Test the search
;$iIndex = _ArraySearch($ASservers, "Name2", 0, 0, 0, 0, 1, 1)
; And display the full array showing that the return is correct
;_ArrayDisplay($ASservers, "Name2 is on Row " & $iIndex)
; Here is the serverarray
; Create a GUI
$hGUI = GUICreate("Unix/Linux DashBoard", 600, 320,50,50, $WS_SYSMENU)
; Create the fields
$srvField1 = GUICtrlCreateInput("<server>",10,240,125,20)
$srvCombo = GUICtrlCreateCombo("", 10, 210, 125, 20)
; Create label
$srvaLabel = GUICtrlCreateLabel("", 145, 215, 40, 20)
$srvbLabel = GUICtrlCreateLabel("", 190, 215, 40, 20)
;create buttons
$CloseButton = GUICtrlCreateButton("Close", 500, 260, 75, 20)
$srvComboButton = GUICtrlCreateButton("Connect", 235, 210, 50, 20)
;Set other vars
$srvString = ""
$srvComboString = ""
; And fill server combo
GUICtrlSetData($srvCombo, $ASservers)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
  Case $CloseButton
  WinClose('')
  Case $srvCombo
            $srvName = GUICtrlRead($srvCombo)
            $iIndex = _ArraySearch($ASservers, $srvName)
            If Not @error Then
            GUICtrlSetData($srvaLabel, $srvArray[$iIndex][1])
   GUICtrlSetData($srvbLabel, $srvArray[$iIndex][2])
  Endif
EndSwitch
WEnd

This is my ini contents

[sERVERLIJST]

Key1=1200|lsrv|P|CBT

Key2=1220|lsrv|A|OMH

Key3=buxus|AIX|P|MCB

Share this post


Link to post
Share on other sites



waardd,

Welcome to the AutoIt forum. :)

GUICtrlSetData only accepts strings, not whole arrays. So you need to extract the data from the array before you use it. This shows you how: :D

; connect to server script v0.1
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

; Declare the array as Global
Global $ASservers
; Fill the array
_populateARRAY()

;Set other vars
$srvString = ""
$srvComboString = ""

; Test the search
;$iIndex = _ArraySearch($ASservers, "Name2", 0, 0, 0, 0, 1, 1)
; And display the full array showing that the return is correct
;_ArrayDisplay($ASservers, "Name2 is on Row " & $iIndex)
; Here is the serverarray

; Create a GUI
$hGUI = GUICreate("Unix/Linux DashBoard", 600, 320, 50, 50, $WS_SYSMENU)
; Create the fields
$srvField1 = GUICtrlCreateInput("<server>", 10, 240, 125, 20)
$srvCombo = GUICtrlCreateCombo("", 10, 210, 125, 20)
; Create label
$srvaLabel = GUICtrlCreateLabel("", 145, 215, 40, 20)
$srvbLabel = GUICtrlCreateLabel("", 190, 215, 40, 20)
;create buttons
$CloseButton = GUICtrlCreateButton("Close", 500, 260, 75, 20)
$srvComboButton = GUICtrlCreateButton("Connect", 235, 210, 50, 20)

; And fill server combo
$sServer_Data = ""
For $i = 1 To UBound($ASservers) - 1
    $sServer_Data &= "|" & $ASservers[$i][1] ; You may need to use another index here <<<<<<<<<<<<<<<<<<<<
Next
GUICtrlSetData($srvCombo, $sServer_Data)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CloseButton
            WinClose('')
        Case $srvCombo
            $srvName = GUICtrlRead($srvCombo)
            $iIndex = _ArraySearch($ASservers, $srvName)
            If Not @error Then
                GUICtrlSetData($srvaLabel, $ASservers[$iIndex][1])
                GUICtrlSetData($srvbLabel, $ASservers[$iIndex][2])
            EndIf
    EndSwitch
WEnd

;Functions
Func win($TITLE, $TEXT)
    If WinExists($TITLE, $TEXT) Then
        If Not WinActive($TITLE, $TEXT) Then
            WinActivate($TITLE, $TEXT)
        EndIf
    EndIf
EndFunc   ;==>win

Func _populateARRAY()
    ; Get the entries
    Local $srvREAD = IniReadSection("srvlist.ini", "SERVERLIJST")
    ; Size the Global array correctly
    Global $ASservers[$srvREAD[0][0] + 1][5]
    ; Declare this Local array outside the loop
    Local $srvREAD2
    For $i = 1 To $srvREAD[0][0]
        ; Split the delimited string into an array
        $srvREAD2 = StringSplit($srvREAD[$i][1], "|")
        ; Now add the elements to the Global array
        For $j = 1 To $srvREAD2[0]
            $ASservers[$i][$j] = $srvREAD2[$j]
        Next
    Next

EndFunc   ;==>_populateARRAY

I moved your functions to the end - that is the more usual place to find them. :)

All clear? ;)

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

When i try your solution it comes up with an error.

C:homewaarddbinscripts_autoitUDB_v3.au3 (72) : ==> Subscript used with non-Array variable.:

Global $ASservers[$srvREAD[0][0] + 1][5]

Global $ASservers[$srvREAD^ ERROR

i'm a bit of a newbee but i get your point... but now for the error?

Share this post


Link to post
Share on other sites

Sorry... i got it.

You changed the location of the ini file :)

Share this post


Link to post
Share on other sites

waardd,

Sorry, that was for my testing - I try not write to my C: drive, especially when testing AutoIt scripts! :)

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
Sign in to follow this  
Followers 0