If you have "subscript out of range" error, instead of TRAPPING it avoid
specifying out of range subscript.
This can be done VERY EASILY.
Subscript has to be GREATER or equal ZERO and SMALLER than BarCount
So all you need to do is to ALWAYS perform this check PRIOR to any subscript
access:
if( bar >= 0 AND bar < BarCount )
{
..... DO THE WORK YOU NEED
}
else
{
// subscript out of range ERROR TRAP HERE
}
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: Ken Close
To: [email protected]
Sent: Monday, August 18, 2008 1:11 PM
Subject: [amibroker] How to "Error Trap" in Automatic Analysis?
I do not recall this being discussed (but of course I forget lots of past
messages).
In making some code to be run in AA by an inexperienced AB user, I want to
error trap some situations that are likely to be encountered and then give a
message to the user instead of the program dropping into the Formula Editor
with a yellow line on the offending line.
In general, is it possible?
I realize the answer is to set up the program to avoid every situation where
the error might occur.
In my case, I have a subscripted formula in a loop which will yield a
"subscript out of range" if the current symbol contains less days of data than
the Parameters are set for.
I set a startdate, calculate a "FirstBar" for the range that is set, and then
use a "FirstBar - 1" subscript, which works fine if the calculated FirstBar is
always greater than the actual first bar. If the data does not exist earlier
than the date set for FirstBar, then the error pops up.
Thus my question: is it possible to sense the error condition and display an
error message of the users choosing?
The less elegant way is to instruct the user that if they see a yellow line
in the Formula Editor, to check that the FirstBar date is set at or after the
beginning of the shortest data symbol.
Comments?
Ken