Jump to content
Sign in to follow this  
avery

Array variable

Recommended Posts

avery

Hello,

I've been reading help files and looking for examples and have tried every single combination I can possible think of and I just can't seem to get this function to work. Can anyone please help me figure out what I'm doing wrong?

Please and thank you if you can help me out.

-Avery Howell

Global $d = 1 ; debug
Global $programsList = @ScriptDir & "\abox_priority_programs_list.txt"
Dim $programsArray
getPrograms()

Func getPrograms()
    _FileReadToArray($programsList, $programsArray)
    q("Inside getPrograms")
    For $x1x = 1 To $programsArray[0]
        q("FR2A: " & $programsArray[$x1x] & " [" & $x1x & "] (" & $programsArray[0] & ")")
        If (StringLeft($programsArray[$x1x], 1) == ";") Then
            If ($d) Then q("Ignoring Comment: " & $programsArray[$x1x] & " " & $x1x)
            Local $nsoa = _ArrayDelete($programsArray, $x1x)
            q("new size of array: " & $nsoa)
            $programsArray[0] = $nsoa ; not sure what to use this or the one below or the other combo's I tried
            ReDim $programsArray[$nsoa] ; not sure what to use this or the one below or the other combo's I tried
                        $programsArray[0] = $programsArray[$programsArray[1]] - 1 ; not sure :(
        EndIf
    Next
EndFunc   ;==>getPrograms

$programsList file contains:

; c1

ACCT05\athowell2*0*3

; c2

ErgoSuite.exe*0*0

;c3

Error Message from SciTe: (the error message always says something about the array but the line number and place it's used changes)

C:\abox\au3\abox_priority\abox_priority.au3 (137) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:


www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org

Share this post


Link to post
Share on other sites
99ojo

Hi,

your problem is the _ArrayDelete (). This causes to crash the for..loop, because it is running until $programsArray[0] -> Arraysize ! before ! deleting elements in your Loop.

So your loop adresses array elements which are not existent at runtime in between for .. loop.

Because i don't know exactly what output you want and i'm not in the mood, it's a hint. Change the logic of your loop, have a look at Do .. Until loop and Function UBound ().

This should give a new start.

;-))

Stefan

Share this post


Link to post
Share on other sites
PsaltyDS

If you will be deleting elements in an array, walk it backwards. That way, deleted element don't impact future operations:

Func getPrograms()
    _FileReadToArray($programsList, $programsArray)
    For $x1x = $programsArray[0] To 1 Step -1
        If (StringLeft(StringStripWS($programsArray[$x1x], 1), 1) == ";") Then _ArrayDelete($programsArray, $x1x) ; Delete comment lines
    Next
    $programsArray[0] = UBound($programsArray) - 1
EndFunc   ;==>getPrograms

:mellow:


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
avery

I'll look at the new start but still don't understand why it doesn't exist when I redim or adjust the value of [0]. The array delete function returns the new size of the array so I have the information I thought was needed to determine the proper size.

All I was trying to do was read a file to array but skip the lines that were comments and I make the comment lines start with a ";".

The file contains:

; c1 (array index 1)

ACCT05\athowell2*0*3 (array index 2)

; c2 (array index 3)

ErgoSuite.exe*0*0 (array index 4)

;c3 (array index 5)

I want to remove the lines that start with ";" so I used StringLeft w/ ";" to match.

The resulting array I'm trying to accomplish is:

ACCT05\athowell2*0*3 (array index 1)

ErgoSuite.exe*0*0 (array index 2)

Thanks for the new start idea I'll try to parse the file to array after it's full using the do loop and see if I end up with the same result. I think I have to redim the array if I re-size it or I get errors.


www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org

Share this post


Link to post
Share on other sites
99ojo

If you will be deleting elements in an array, walk it backwards. That way, deleted element don't impact future operations:

Func getPrograms()
    _FileReadToArray($programsList, $programsArray)
    For $x1x = $programsArray[0] To 1 Step -1
        If (StringLeft(StringStripWS($programsArray[$x1x], 1), 1) == ";") Then _ArrayDelete($programsArray, $x1x) ; Delete comment lines
    Next
    $programsArray[0] = UBound($programsArray) - 1
EndFunc   ;==>getPrograms

:mellow:

Clever one you are.....

Share this post


Link to post
Share on other sites
avery

You are my Hero!


If you will be deleting elements in an array, walk it backwards. That way, deleted element don't impact future operations:

Func getPrograms()
    _FileReadToArray($programsList, $programsArray)
    For $x1x = $programsArray[0] To 1 Step -1
        If (StringLeft(StringStripWS($programsArray[$x1x], 1), 1) == ";") Then _ArrayDelete($programsArray, $x1x) ; Delete comment lines
    Next
    $programsArray[0] = UBound($programsArray) - 1
EndFunc   ;==>getPrograms

:mellow:


www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org

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  

×