Jump to content

delete a line in a xml file


Recommended Posts

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

Link to comment
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
Link to comment
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...
Link to comment
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.

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...