Existence testing
Posted: Thu Sep 02, 2010 8:21 am
For a lot of the programs I write, it would be beneficial to check to see if a Page or a Series (or really any object) already exists in my workfile. Instead I often find myself coding a much larger repetitive code section instead of being able to loop through a concise code template. I've scoured to look for an exists() test. I've finally set to write one. My concerns stem from interrupting the routine (via 'ESC') while in mid subroutine. If I interrupt at the wrong time, effectively I've allowed for an increase in errors which I might not catch.
Here's the other thing, if I try to call an error catching function on a series which does not exist, it should punt when the function call fails at the series declaration, effectively erroring on the error check.
This has *not* been tested since I'm still making sure that I've got the concept thought through well enough.
Any thoughts would be appreciated.
Here's the other thing, if I try to call an error catching function on a series which does not exist, it should punt when the function call fails at the series declaration, effectively erroring on the error check.
This has *not* been tested since I'm still making sure that I've got the concept thought through well enough.
Any thoughts would be appreciated.
Code: Select all
' Using @errorcount and @maxerrs: get the current conditions and settings
' attempt to perform a null operation and confirm @errcount has not incremented
' return 1 if exists, return 0 if not
subroutine local exist(series passed_series, scalar ret_val)
%beg_err_ct = @errorcount
%max_err_ct = @maxerrs
%end_err_ct = @errorcount
setmaxerrs = %max_err_ct + 1
genr temp_series = passed_series
ret_val = 0
if %end_err_ct = %beg_err_ct then
' the set existed
ret_val = 1
setmaxerrs = %max_err_ct -1
else
'the set did not exist.
seterrcount = @errorcount - 1
setmaxerrs = %max_err_ct -1
endif
endsub