Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Broken Types?
Message
From
03/10/2005 18:15:46
 
 
To
03/10/2005 17:17:08
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01055653
Message ID:
01055672
Views:
15
This message has been marked as a message which has helped to the initial question of the thread.
>I know weak typing has been a useful feature in FoxPro, but sometimes I want to enforce strong typing. But according to the following code, that's not possible!
>
>
>?squareit("5")
>
>
>FUNCTION squareit
>	LPARAMETERS x as Double
>	
>	?"have we encountered a problem yet?"
>
>	RETURN x * x
>ENDFUNC
>
>
>My initial thought was I should get an error on the call to squareit(), since I am passing a character type when it expects a double. But the error doesn't happen until I perform the calculation. This isn't right! If the caller screws up the function call, I want the error to originate there, not buried in the well-debugged function!
>
>I haven't noticed this before because I assummmed FoxPro was enforcing my explicit type. Am I doing something wrong, or is this just one of FoxPro's quirks?
>
>Using VFP 9, no service pack...
>
>Brian Vander Plaats
>
>Brian

This is by design.
It is not possible to declare the type for a variable,
or to prevent that a variable changes type.

If you want to check the type you have to expressly do it:
?squareit("5")

FUNCTION squareit
	LPARAMETERS x as Double
	IF NOT VARTYPE(m.x)=="N"
	  ERROR "have we encountered a problem yet?"
          RETURN NULL
        ENDIF
	RETURN x * x
ENDFUNC
Previous
Reply
Map
View

Click here to load this message in the networking platform