Sign in to follow this  
Followers 0
develogy

Problem placing Array from FileListToArray in another array to put in ListView

3 posts in this topic

I am attempting to build a list from a series of directories under the ScriptPath of standalone system monitor applications that have also been built in AutoIt

The goal is to get the list of directories that Start with "Monitor-", then place them in an array, then when refreshing the status ListView, I will also be checking a text file for each one to get its current status, but for now that is just being filled in with "PAUSED".

I can get the correct directories, but when I try to loop through it to put in the list view I get this error:

J:ProjectsSysMonMonStatus.au3 (39) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aItems[$i][0] = $MonitorList[$b][0]

$aItems[$i][0] = ^ ERROR

Any ideas from all of you AutoIt Wizards?

 

;************ Includes ************
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
;************ Includes ************
AdlibRegister("RefreshMonitorList",500)
Global $MonitorListView
RefreshMonitorList()
GUICreate("Monitor Status Check", 400, 300)
$MonitorListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState(@SW_SHOW)
; Add columns
_GUICtrlListView_AddColumn($MonitorListView, "Monitor Name", 100)
_GUICtrlListView_AddColumn($MonitorListView, "Status", 100)


Func GetMonitors()
Local $MonitorList = _FileListToArray(@ScriptDir, "Monitor-*", 2)
    If @error = 1 Then
        MsgBox(4096, "", "Path was invalid.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(4096, "", "No Monitors were found.")
        Exit
    EndIf
    ; Display the results returned by _FileListToArray.
    ;_ArrayDisplay($MonitorList, "$MonitorList")
    Return $MonitorList
EndFunc


Func RefreshMonitorList()
$MonitorList = GetMonitors()
_GUICtrlListView_DeleteAllItems($MonitorListView)
Local $aItems[5000][2]
For $i = 0 To UBound($MonitorList) - 1
        $b = $i + 1
        $aItems[$i][0] = $MonitorList[$b][0]
    $aItems[$i][1] = "PAUSED"
Next
    _GUICtrlListView_AddArray($MonitorListView, $aItems)
EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

develogy,

_FileListToArray only returns a 1D array - you are using 2D syntax to access it. Plus you are going too far into the array - see below. ;)

This should work:

Local $aItems[UBound($MonitorList) - 1][2]           ; Why 5000 when you know how big it needs to be?
For $i = 0 To UBound($MonitorList) - 2               ; Otherwise $i + 1 will fail as it is outside the bounds
    $aItems[$i][0] = $MonitorList[$i + 1]            ; Use 1D syntax here
    $aItems[$i][1] = "PAUSED"
Next
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

Thanks Melba,

You were spot on.

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