Jump to content
Sign in to follow this  
handro

Array dimension range exceeded (Bug?)

Recommended Posts

handro

CODE
$Line2=0

Do

$Line2+=1

$LineRead2=FileReadLine("Database.txt",$Line2)

$Split2=StringSplit($Lineread2,",")

MsgBox(0,"Worked:",$Split2[2])

Until $Lineread2=""

Error: C:\Documents and Settings\Nobody\Desktop\Program\Array.au3 (16) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Note: The program successfully opens a messagebox and shows Split[2] from all 4 lines, but If I have it read a string from a file and replace it with Split[2] it won't do it until this error is resolved. (my guess, since it didint work)

Ignore the line number, I have more code above this that isn't associated with this particular loop.

Edited by handro

Share this post


Link to post
Share on other sites
-Ultima-

Trace through and see what's happening. Every time you split the string, the number of elements becomes less and less. Eventually, you reach a point where you're trying to split an empty string with the comma character, which results in an array [1, ""] -- only 2 elements with the max index being 1.


[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Share this post


Link to post
Share on other sites
Valuater

Trace through and see what's happening. Every time you split the string, the number of elements becomes less and less. Eventually, you reach a point where you're trying to split an empty string with the comma character, which results in an array [1, ""] -- only 2 elements with the max index being 1.

???

He is reading a file

???

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
handro

CODE
$Line2=0

Do

$Line2+=1

$LineRead2=FileReadLine("Database.txt",$Line2)

If @error = -1 Then ExitLoop

$Split2=StringSplit($Lineread2,",")

$Replace=FileReadLine("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",48)

$Worked=StringReplace($Replace,"John Williams",$Split[2],0,1)

$File=FileOpen("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",1)

If IsArray($Split2) And $Split2[0] >= 2 Then FileWriteLine($File,$Worked)

Until $Lineread2=""

When I would do this for example, it doesn't replace John Williams with what I have in my database.txt file

I changed up to actually editing the files since there were no array errors this time

Edited by handro

Share this post


Link to post
Share on other sites
handro

The only issue I could find is that when i do

MsgBox(0,"Worked:",$File)

it returns:

1(clicked ok)

2 ( ok)

3 (ok)

4 (ok)

It should return the file names ( I created them using a do loop earlier in the program, the first part has no problems making them, just modifying them after theyre made)

"image.1"

"image.2"

My database file contains 4 lines and looks like this:

1, Name, image.jpg

2, Name, image.jpg

etc

Heres the code again:

CODE
$Line2=0

Do

$Line2+=1

$LineRead2=FileReadLine("Database.txt",$Line2)

If @error = -1 Then ExitLoop

$Split2=StringSplit($Lineread2,",")

$Replace=FileReadLine("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",48)

$Worked=StringReplace($Replace,"John Williams",$Split[2],0,1)

$File=FileOpen("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",1)

If IsArray($Split2) And $Split2[0] >= 2 Then FileWriteLine($File,$Worked)

Until $Lineread2=""

Edited by handro

Share this post


Link to post
Share on other sites
Valuater

Dunno!!!

***** $DirN and $Split are unknown to me

$Line2=0
Do
$Line2+=1
$LineRead2=FileReadLine("Database.txt",$Line2)
If @error = -1 Then ExitLoop
    
$Split2=StringSplit($Lineread2,",")
If IsArray($Split2) And $Split2[0] >= 2 Then
    $Replace=FileReadLine("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",48) ;***** $DirN and $Split are unknown to me
    $Worked=StringReplace($Replace,"John Williams",$Split[2],0,1)
    $File=FileOpen("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",1)
    FileWriteLine($File,$Worked)
    FileClose($File)
EndIf
Until $Lineread2=""

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
handro

ah i see,

$DirN=StringSplit($Split[3],".")

$Split=StringSplit($Lineread2,",")

Those are the strings I forgot to mention, I am sorry

Edited by handro

Share this post


Link to post
Share on other sites
PsaltyDS

ah i see,

$DirN=StringSplit($Split[3],".")

$Split=StringSplit($Lineread2,",")

Those are the strings I forgot to mention, I am sorry

I didn't get that you seemed to get $Split and $Split2 both equal to the same array.

So, is this what it's supposed to look like?

$Line2 = 0
Do
    $Line2 += 1
    $LineRead2 = FileReadLine("Database.txt", $Line2)
    If @error = -1 Then ExitLoop

    $Split = StringSplit($LineRead2, ",")
    If IsArray($Split) And $Split[0] >= 2 Then
        $DirN = StringSplit($Split[3], ".")
        $Replace = FileReadLine("C:\Test\" & $DirN[1] & "." & $Split[1] & "\cap2.htm", 48)
        $Worked = StringReplace($Replace, "John Williams", $Split[2], 0, 1)
        $File = FileOpen("C:\Test\" & $DirN[1] & "." & $Split[1] & "\cap2.htm", 1)
        FileWriteLine($File, $Worked)
        FileClose($File)
    EndIf
Until $LineRead2 = ""

:)


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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.