Jump to content
Sign in to follow this  
Aeterna

Why am I getting this error? (Arrays)

Recommended Posts

Aeterna

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

CODE

Local $Follows[1000]

$FollowFile = "c:\follows.txt"

_FileReadToArray($FollowFile, $Follows)

$FollowNum = 0

$Follow = $Follows[$FollowNum]

func NextFollow()

$FollowNum = $FollowNum + 1

$PageNum = 1

$follow = $Follows[$FollowNum]

EndFunc

I'm getting this error when my program calls the NextFollow() function and it gets to the 3rd line of the function "$follow = $Follows[$FollowNum]"

Whats going on?

Share this post


Link to post
Share on other sites
Yashied

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

CODE

Local $Follows[1000]

$FollowFile = "c:\follows.txt"

_FileReadToArray($FollowFile, $Follows)

$FollowNum = 0

$Follow = $Follows[$FollowNum]

func NextFollow()

$FollowNum = $FollowNum + 1

$PageNum = 1

$follow = $Follows[$FollowNum]

EndFunc

I'm getting this error when my program calls the NextFollow() function and it gets to the 3rd line of the function "$follow = $Follows[$FollowNum]"

Whats going on?

If $FollowNum > 999 ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.

Share this post


Link to post
Share on other sites
Aeterna

If $FollowNum > 999 ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.

But this is happening when FollowNum is at like 2 or 3

Share this post


Link to post
Share on other sites
Authenticity

You don't need to declare Follows as an array variable, it'll be an array when returning from _FileReadToArray function. The number of lines, which is also the upper bound of the array is stored into the first subscript. So if $Follows[0] = 50 then the highest valid subscript is $Follows[50].

Share this post


Link to post
Share on other sites
Aeterna

You don't need to declare Follows as an array variable, it'll be an array when returning from _FileReadToArray function. The number of lines, which is also the upper bound of the array is stored into the first subscript. So if $Follows[0] = 50 then the highest valid subscript is $Follows[50].

Hmm, I'm not sure I understand.

Basically I have a list of names, 1 per line in a txt file which is being brought into an array

$FollowFile = "c:\follows.txt"

_FileReadToArray($FollowFile, $Follows)

$Follow = $Follows[$FollowNum]

$Follow is the name of the person I want to be using, called by the index $FollowNum which counts up so that after my code has ran, it switches to the next person.

func NextFollow()

$FollowNum = $FollowNum + 1

$follow = $Follows[$FollowNum]

EndFunc

Does that clarify what I'm doing? Or maybe you could rephrase your answer?

Share this post


Link to post
Share on other sites
Richard Robertson

You need to check to make sure you don't go out of the array. Use UBound($Follows) to get the max that you can go to.

Share this post


Link to post
Share on other sites
John117

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

CODE

Local $Follows[1000]

$FollowFile = "c:\follows.txt"

_FileReadToArray($FollowFile, $Follows)

$FollowNum = 0

$Follow = $Follows[$FollowNum]

func NextFollow()

$FollowNum = $FollowNum + 1

$PageNum = 1

$follow = $Follows[$FollowNum]

EndFunc

I'm getting this error when my program calls the NextFollow() function and it gets to the 3rd line of the function "$follow = $Follows[$FollowNum]"

Whats going on?

No idea what you are doing . . . .

Hope this helps

$FollowFile = "c:\follows.txt"
If Not _FileReadToArray($FollowFile, $Follows) Then
MsgBox(4096, "Error", " Error reading " & $FollowFile & " log to Array error:" & @error)
Exit
EndIf


For $i = 0 to UBound($Follows) -1
$Follow = $Follows[$i]
$PageNum = 1
Next

Actually $Follows[0] = the count not the first value, so the $i will need to start at 1 and go to the full without the -1 at the end.

Edited by Hatcheda

Share this post


Link to post
Share on other sites
Aeterna

If i remove:

Local $Follows[999]

Then I get the error:

==> Variable used without being declared.:

If Not _FileReadToArray($FollowFile, $Follows) Then

If Not _FileReadToArray($FollowFile, ^ ERROR

Share this post


Link to post
Share on other sites
Authenticity

Dim $Follows

_FileReadToArray("C:\something.txt", $Follows)

Edit: Forgive me:

Local $Follows

_FileReadToArray("C:\something.txt", $Follows)

;]

Edited by Authenticity

Share this post


Link to post
Share on other sites
John117

If i remove:

Local $Follows[999]

Then I get the error:

==> Variable used without being declared.:

If Not _FileReadToArray($FollowFile, $Follows) Then

If Not _FileReadToArray($FollowFile, ^ ERROR

Always a good idea to declare all variables at the top

Dim . . .

Global . . .

Local . . .

Depending on your intended use.

keep the error code around the filereadtoarray . . . . it's good for letting you know what's going on. . . .

Edited by Hatcheda

Share this post


Link to post
Share on other sites
Aeterna

Always a good idea to declare all variables at the top

Dim . . .

Global . . .

Local . . .

Depending on your intended use.

keep the error code around the filereadtoarray . . . . it's good for letting you know what's going on. . . .

Thanks everybody, I got it working. There was some other ordering issues that was causing it to not function properly as well, but I couldn't have solved it without your advice! keep up the good work guys ^_^

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  

×