waardd Posted December 15, 2011 Share Posted December 15, 2011 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?expandcollapse popup; 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 WEndThis is my ini contents[sERVERLIJST]Key1=1200|lsrv|P|CBTKey2=1220|lsrv|A|OMHKey3=buxus|AIX|P|MCB Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 15, 2011 Moderators Share Posted December 15, 2011 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: expandcollapse popup; 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 ;==>_populateARRAYI 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 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 Link to comment Share on other sites More sharing options...
waardd Posted December 15, 2011 Author Share Posted December 15, 2011 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? Link to comment Share on other sites More sharing options...
waardd Posted December 15, 2011 Author Share Posted December 15, 2011 Sorry... i got it. You changed the location of the ini file Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 15, 2011 Moderators Share Posted December 15, 2011 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 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 Link to comment Share on other sites More sharing options...
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