Jump to content
Sign in to follow this  
RagnaroktA

Simple Array -> ListView Problem

Recommended Posts

RagnaroktA

Okay, so I know that this is a simple fix, I just cant for the life of me figure it out. Someone point me in the right direction...

Func _ListFiles($sPath)
        Local $aFileList, $i = 1
        $aFileList = _FileListToArray($sPath, "*", 1)
        If @error = 1 Then
            MsgBox(48, $sTitle, "No files were found in the directory specified." & @CRLF & @CRLF & $sPath)
            Exit
        Endif

        For $i = 1 To $aFileList[0]
            $lvFilesItem = GUICtrlCreateListViewItem($i & "|" & $sPath & "|" & StringStripCR($aFileList[$i]), $lvFiles)
    
;        If $lvEven Then
;            $lvEven = 0
;        Else
;            $lvEven = 1
;            GUICtrlSetBkColor($lvItem, $GUIBkColor)
;        EndIf
        Next
   ; _ArrayDisplay($aFileList, "$FileList")
    EndFunc; ==> _ListFiles

The above function is supposed to populate a list view with the information returned by _FileListToArray. It does that, but it wont stop. It continually cycles through, re-adding the same array to the list view. What did I do wrong? I cant see the error in the logic, and everything I've tried left me with the same situation. Any help is greatly appreciated.


Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites
RagnaroktA

don' t see anything wrong with this code ...

And therein lies my problem. I dont either. :)

All I know is instead of stopping at $aFileList[0], it continues on until the list view is maxed out and cant accept more lines.

...

Edited by RagnaroktA

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites
Jos

And therein lies my problem. I dont either. :)

All I know is instead of stopping at $aFileList[0], it continues on until the list view is maxed out and cant accept more lines.

...

Do you have a script that shows this issue which I can test with ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
PsaltyDS

And therein lies my problem. I dont either. :)

All I know is instead of stopping at $aFileList[0], it continues on until the list view is maxed out and cant accept more lines.

...

Your problem is your error checking. _FileListToArray() can return other @error besides 1, which is the only one you test for. Try this:

Func _ListFiles($sPath)
    Local $aFileList, $i = 1
    $aFileList = _FileListToArray($sPath, "*", 1)
    If @error Then
        MsgBox(48, $sTitle, "Error listing files:" & @CRLF & _
                "Directory: " & $sPath & @CRLF & _
                "@error = " & @error)
        Exit
    EndIf
    For $i = 1 To $aFileList[0]
        $lvFilesItem = GUICtrlCreateListViewItem($i & "|" & $sPath & "|" & StringStripCR($aFileList[$i]), $lvFiles)
        ;         If $lvEven Then
        ;             $lvEven = 0
        ;         Else
        ;             $lvEven = 1
        ;             GUICtrlSetBkColor($lvItem, $GUIBkColor)
        ;         EndIf
    Next
    ; _ArrayDisplay($aFileList, "$FileList")
EndFunc   ;==>_ListFiles

I'll bet you're getting an @error, but not 1.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
RagnaroktA

Do you have a script that shows this issue which I can test with ?

I do, but it's just shy of 700 lines, and nowhere near complete. Very very sloppy at the moment.

I get an @error of 1, and it is still just adding the same array over and over again into the listview...


Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites
PsaltyDS

I get an @error of 1, and it is still just adding the same array over and over again into the listview...

An @error of 1 from _FileListToArray() should have exited the script completely without adding anything. Did you try my version of the error handling in post #5?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
RagnaroktA

An @error of 1 from _FileListToArray() should have exited the script completely without adding anything. Did you try my version of the error handling in post #5?

:)

I did, that also gave me an @error of 1.

It does the exact same thing. It's retarded, or I'm retarded. One of the two.


Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

Share this post


Link to post
Share on other sites
PsaltyDS

I did, that also gave me an @error of 1.

It does the exact same thing. It's retarded, or I'm retarded. One of the two.

Well you can't get an @error from _FileListToArray() and then go on to try and use the returned array, because there won't be one (at least no a valid one). The @error values from the help file under _FileListToArray() are:

Return Value

@Error: 1 = Path not found or invalid

2 = Invalid $sFilter

3 = Invalid $iFlag

4 = No File(s) Found

So if you are seeing @error = 1 then your path is invalid at the $sPath input parameter.

In addition, both your original snippet and my modification would exit the script on @error = 1, so how are you getting that and still seeing runaway additions to the array? You should just be seeing the script suddenly exit (after an error MsgBox() pops up).

:D

P.S. Looking at the full script, it doesn't look like the problem is in that function anyway. In the following While/WEnd loop, what exits the loop and keeps it from adding the same files over and over again? (commented lines removed for clarity)

While 1
    Sleep(20)
    If $iGUI = 'GUI3' Then
        If $ibGUI2Directory1 <> "" Then
            $ibGUI2Directory1Data = GUICtrlRead($ibGUI2Directory1)
            _ListFiles($ibGUI2Directory1Data)
        Else
        EndIf
    EndIf
WEnd

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
RagnaroktA

Well you can't get an @error from _FileListToArray() and then go on to try and use the returned array, because there won't be one (at least no a valid one). The @error values from the help file under _FileListToArray() are:

So if you are seeing @error = 1 then your path is invalid at the $sPath input parameter.

In addition, both your original snippet and my modification would exit the script on @error = 1, so how are you getting that and still seeing runaway additions to the array? You should just be seeing the script suddenly exit (after an error MsgBox() pops up).

:D

P.S. Looking at the full script, it doesn't look like the problem is in that function anyway. In the following While/WEnd loop, what exits the loop and keeps it from adding the same files over and over again? (commented lines removed for clarity)

While 1
    Sleep(20)
    If $iGUI = 'GUI3' Then
        If $ibGUI2Directory1 <> "" Then
            $ibGUI2Directory1Data = GUICtrlRead($ibGUI2Directory1)
            _ListFiles($ibGUI2Directory1Data)
        Else
        EndIf
    EndIf
WEnd

:)

You're completely right, I meant to move that out of there, it was there just to see if it was hitting the function in the first place. Noob mistake, thanks a bunch for all of your help. :D

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki

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  

×