#156542 - 2006-02-03 12:15 AM
Problem with @ERROR output -- yielding funny results...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
The code below is a snippet of a larger bit of code that runs fine; it's the script below I'm having problems with...
Edit: Added $vars for the conditional in question...
Code:
$OpenReorgFile = Open(3,$ReorgFile,2) $PhoneDirFile = @ScriptDir + '\Balad_Telephone_Book.csv' $OpenPDFile = Open(4,$PhoneDirFile,2) $OutputFile = @ScriptDir + '\Morale_Call_Output.csv' $OpenOutputFile = Open(5,$OutputFile,5)
If $OpenReorgFile = 0 AND $OpenPDFile = 0 AND $OpenOutputFile = 0 $rLine = ReadLine(3) Do $rArrLine = Split($rLine,',') $pdLine = ReadLine(4) Do $pdArrLine = Split($pdLine,',') ? $pdArrLine[4]
$pdLine = ReadLine(4) Until @ERROR <> 0 $rLine = ReadLine(3) Until @ERROR <> 0 Else ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif
I don't know why but the very first conditional is working because the files are getting created and stuff but my ELSE code is executing too... BUT it's executing as "Error: 0 -- The operation completed successfully." Does that make sense?
Edit2: Interestingly enough, when I comment my whole second Do loop, it runs fine echoing the first array... if that helps at all.
Edited by thepip3r (2006-02-03 12:52 AM)
|
Top
|
|
|
|
#156546 - 2006-02-03 03:33 AM
Re: Problem with @ERROR output -- yielding funny results...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
Ok, some further progress... when I do some error trapping, I actually found in the loop where the error is occurring and the following error is reported by @ERROR/@SERROR:
"Error: -1 -- Error(317 / 13D) while retrieving error information for FFFFFFFF"
...then that's when it gives the KiX beep and says: "array reference out of bounds"
If it helps anyone to see where the error gets trapped:
Code:
$OpenReorgFile = Open(3,$ReorgFile,2) $PhoneDirFile = @ScriptDir + '\Balad_Telephone_Book.csv' $OpenPDFile = Open(4,$PhoneDirFile,2) $OutputFile = @ScriptDir + '\Morale_Call_Output.csv' $OpenOutputFile = Open(5,$OutputFile,5)
If $OpenReorgFile = 0 AND $OpenOutputFile = 0 AND $OpenPDFile = 0 $rLine = ReadLine(3) Do $rArrLine = Split($rLine,',') ? '1: ' + $rArrLine[4] $pdLine = ReadLine(4) If @ERROR <> 0 ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif sleep 5 Do $pdArrLine = Split($pdLine,',') ? '2: ' + $pdArrLine[4] $pdLine = ReadLine(4) Until @ERROR <> 0 $rLine = ReadLine(3) Until @ERROR <> 0 Else ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif
If grabs the first variable in the first loop, runs it against the whole file in the second loop, grabs the second variable for the first loop but when it goes for the first ReadLine() in the second instance of the second loop is when I get the error.
Anyone have any ideas?
Edited by thepip3r (2006-02-03 03:51 AM)
|
Top
|
|
|
|
#156547 - 2006-02-03 10:43 AM
Re: Problem with @ERROR output -- yielding funny results...
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Add some code to check that your file opens have worked. Don't ever assume that anything will work, because at some point it won't.
Make sure that you are not trying to read past the end of any of your files.
If you are going to split a line you need to check the size of the array after the split. If you read a blank line, or a line which has less fields than you expect then there is a chance that the array is not as big as you were expecting. When you attempt to reference a cell past the end of the array you will get an "out of bounds" error.
If you don't want to check the size each time and the lines are of varying lengths then a trick I use is to add enough blank elements to the end of the line to ensure that the array reference will never be out of bounds.
For example the "+',,,,'" in the following code ensures that there is always at least 5 elements in the array, so that the next line can never cause an out-of-bounds error.
Quote:
$rArrLine = Split($rLine+',,,,',',') ? '1: ' + $rArrLine[4]
|
Top
|
|
|
|
#156551 - 2006-02-04 12:32 AM
Re: Problem with @ERROR output -- yielding funny results...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
Ok, that might not be my problem then because when I run the script where I close the inner file everytime on the loop, I get a file handle error. If I was to use the freefilehandle() function, how would I be sure that I got the file handle for the file handle in question? Am I even trying to open/close the file the correct way?
Code:
$OpenReorgFile = Open(3,$ReorgFile,2) $PhoneDirFile = @ScriptDir + '\Balad_Telephone_Book.csv' $OpenPDFile = Open(4,$PhoneDirFile,2) $OutputFile = @ScriptDir + '\Morale_Call_Output.csv' $OpenOutputFile = Open(5,$OutputFile,5)
If $OpenReorgFile = 0 AND $OpenOutputFile = 0 $rLine = ReadLine(3) Do $rArrLine = Split($rLine+',,,,',',') ? '1: ' + $rArrLine[4] If $OpenPDFile = 0 $pdLine = ReadLine(4) If @ERROR <> 0 ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif sleep 5 While @ERROR = 0 $pdArrLine = Split($pdLine+',,,,',',') ? '2: ' + $pdArrLine[4] $pdLine = ReadLine(4) Loop $ = Close(4) Endif $rLine = ReadLine(3) Until @ERROR <> 0 Else ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif
$ = Close(3) $ = Close(5)
|
Top
|
|
|
|
#156552 - 2006-02-04 12:39 AM
Re: Problem with @ERROR output -- yielding funny results...
|
thepip3r
Hey THIS is FUN
Registered: 2005-03-02
Posts: 350
|
well this didn't work:
Code:
$OpenReorgFile = Open(3,$ReorgFile,2) $PhoneDirFile = @ScriptDir + '\Balad_Telephone_Book.csv' $OutputFile = @ScriptDir + '\Morale_Call_Output.csv' $OpenOutputFile = Open(5,$OutputFile,5)
If $OpenReorgFile = 0 AND $OpenOutputFile = 0 $rLine = ReadLine(3) Do $rArrLine = Split($rLine+',,,,',',') ? '1: ' + $rArrLine[4] $handle = FreeFileHandle() If Open($handle,$PhoneDirFile,2) = 0 $pdLine = ReadLine(4) If @ERROR <> 0 ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif sleep 5 While @ERROR = 0 $pdArrLine = Split($pdLine+',,,,',',') ? '2: ' + $pdArrLine[4] $pdLine = ReadLine(4) Loop $ = Close(4) Endif $rLine = ReadLine(3) Until @ERROR <> 0 Else ? 'Error: ' + @ERROR + ' -- ' + @SERROR Endif
$ = Close(3) $ = Close(5)
...this code won't even allow me to parse the file the first time...
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|