serr57 Posted June 14, 2010 Posted June 14, 2010 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
Juvigy Posted June 14, 2010 Posted June 14, 2010 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
serr57 Posted June 14, 2010 Author Posted June 14, 2010 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...
Juvigy Posted June 14, 2010 Posted June 14, 2010 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.
serr57 Posted June 14, 2010 Author Posted June 14, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now