My Display program has the facility to call various functions, most of which are held in a separate library and so can be added to by the user. The functions are accessible from a combo-box which is populated from the library at the start of the program, which merely looks for "DEFFN" and adds that line to the box. The problem is forgetting the correct number of parameters or making a mistake in them such as omitting quotes around a string or a comma that separates parameters - we've all done the kind of thing.
The line that was being executed at the time is sl$ and a mistake in the function call will generate an error, some of which are trapped. PROCwarn() displays a dialog box with a title and a message. text% is a previously defined block used for holding text for various purposes.
Code: Select all
DEFPROCerror:LOCALerr$
CASEERR OF
WHEN9:err$="You have omitted a quotation mark somewhere in your function call to"
err$+=CHR$10+sl$
WHEN26:err$="There is no such variable - which may be a programming error or "
err$+=CHR$10+"a missing opening quotation mark. The error was in"
err$+=CHR$10+sl$
WHEN31:err$="You do not have the correct number of parameters in the call to"
err$+=CHR$10+sl$
IFINSTR(err$,"line")>0err$+=CHR$10+CHR$10+"If you have called FNline you may need FNfancyline."
IFINSTR(err$,"angle")>0err$+=CHR$10+CHR$10+"If you have called FNangled you may need FNanglet."
OTHERWISE
PROCtwarn("Error handler",REPORT$+" at line "+STR$ERL):PROCquit:END
ENDCASE
IFINSTR(err$,"|NFN")>0THEN
i%=INSTR(err$,"|NFN"):j%=INSTR(err$,"(",i%)
func$=MID$(err$,i%+2,j%-i%-2)
SYS"GetDlgItem",!editdlg%,439TOcombo%
SYS"SendMessage",combo%,332,-1,func$TOindex%
SYS"SendMessage",combo%,328,index%,text%TOlen%
err$+=CHR$10+"For a call to "+func$+" you need"+CHR$10+$$text%
ENDIF
IFerr$>""PROCwarn("Error handler",err$)
ENDPROC
This provides output such as the following, which I hope is more useful to the user than a bald "Missing parameter". "|N" is the code which tells the Display program that what follows is a function to be executed.
You do not have the correct number of parameters in the call to
|NFNring(200,200)
For a call to FNring you need
FNring(x%,y%,size%,col%,bg%)