Sign in to follow this  
Followers 0
serr57

delete a line in a xml file

5 posts in this topic

Hi everybody,

I have a xml file where a date line is present.

I would like to delete this line.

My script is running well, but at the and I get this message:

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

I don't understand why.

Here is my script:

#include <Array.au3>
#include <File.au3>

Dim $sFile = "My xml file"
Dim $aLines
_FileReadToArray($sFile, $aLines)
_ArrayDelete($aLines,2)
FileDelete($sFile)
For $i=1 to $aLines[0]
   If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i])
Next

Does anybody can help and explain this to me?

many thanks

serr57

Share this post


Link to post
Share on other sites



It looks like you need to change:

For $i=1 to $aLines[0]
   If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i])
Next

to

For $i=1 to Ubound($aLines)-1
   If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i])
Next

Share this post


Link to post
Share on other sites

It looks like you need to change:

For $i=1 to $aLines[0]
   If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i])
Next

to

For $i=1 to Ubound($aLines)-1
   If $aLines[$i]<>"" Then FileWriteLine($sFile,$aLines[$i])
Next

Many thanks, It work now, but I don't understand the reason why...

Share this post


Link to post
Share on other sites

the array has 150 elements (for example) but as the counting starts at 0

the last element has number 149.

$i=1 to $aLines[0]

This means from 1 to 150 but as there is no element with number 150 it gives error.

It would be correct (not quite) : $i=1 to $aLines[0]-1 .

As $aLines[0] may not always contain the number of elements in the array , always use

the Ubound() function which returns the number of elements in the array.

Share this post


Link to post
Share on other sites

the array has 150 elements (for example) but as the counting starts at 0

the last element has number 149.

$i=1 to $aLines[0]

This means from 1 to 150 but as there is no element with number 150 it gives error.

It would be correct (not quite) : $i=1 to $aLines[0]-1 .

As $aLines[0] may not always contain the number of elements in the array , always use

the Ubound() function which returns the number of elements in the array.

Many thanks Juvigy for your explanations

See you may be for my next post

bye

serr57

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