Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UDF triggering an error

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
I'm creating a UDF that takes parameters. If an attempt is made to access the function with the wrong parameter type, I want to trigger error 11, "Function argument value, type, or count is invalid". I put this at the beginning of my function:

if vartype(param1)!='C' && parameter is wrong type
error 11
return .F.
endif

This is ok, but it generates the error in my function on the "error" line. What I really want to do is generate the error in the calling program on the line that called my function. How would I go about doing this?
 
VFP is a loosely-typed language, it means no native way to do what you want.
I don't know what is wrong with just checking the type of the parameters b4 you call your function.
Also I don't know why you want to use the native error message for VFP eventhough it gives the user a Cancel option
and it shows the VFP native icon (the fox) to your users.
But, assuming that you have your reasons for this here is one of many ways to do it.
Code:
ln=9
ll=3

IF TypeCheck() AND TypeRes(ln,LL)
ENDIF

FUNCTION TypeRes
PARAMETERS lnVal,llVal
?? lnVal
?? llVal	
RETURN

FUNCTION TypeCheck
RETURN IIF(VARTYPE(ln)="N" AND VARTYPE(ll)="L",.T.,"STRING")
IF you run this program you will have a type error, but be aware that this is a trick because the type error has nothing to do with your function, it is the wrong return type of TypeCheck() which was suppose to return logic to the IF statment SO
IF TYPE STRING AND TYPE LOGIC && ERROR
But if your parameters types are ok, TypeCheck() will return true and the if statment has to execute your function
Hope this will help
Walid Magd
Engwam@Hotmail.com
 
Thanks for the response, Walid. The reason for wanting to generate the error in the calling program is just to simplify debugging for the program once I have the function bug-free. I can still trace back through the stack to see what line called the function, so it's not a big deal...it just would have been nice to have it show exactly where the error occurred.
 
Why not use the ASSERT function, it enables you to debug. I take it, this is development environment specific.

HTH,

Weedz (Wietze Veld) They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best. - Steve McConnell
 
*nod* This is just for personal use in the development environment, but I'm fairly new to VFP and haven't figured out how to use ASSERT yet...along with quite a few other things. Maybe it's time I learned it now? :eek:)
 
Hi.. Click on the link.. for he following FAQ
How do I use ASSERTS to test for errors?
faq184-62
:) ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top