Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Type function is not smart enough
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00714883
Message ID:
00714962
Views:
27
>>
>>theFld=thisform.edtReplaceFld.value && "trimzero(StNumExt)"
>>theType=type(m.theFld)
&& Returns U
>>
>>I dont' think, I can use & or evaluate function here...
>
>IMO, you can't avoid traping the error in this case (via ON ERROR, or Error method)
>
>theFld=thisform.edtReplaceFld.value && "trimzero(StNumExt)"
>ON ERROR m.VarToCheck = Null
>m.VarToCheck = eval(theFld)
>ON ERROR   && whatever was before
>? vartype(m.VarToCheck)  && this will not fail
>
>
>If you want a more elegant solution, define an "evaluator" class with error control, and use
>
>oEvaluator = createobject("Evaluator")
>m.VarToCheck = oEvaluator.Eval(theFld) && avoids placing ON ERROR in each evaluation
>? vartype(m.VarToCheck)  && this will not fail
>
>
>Regards,

Here is my own solution:
*******************************************************************
*  Description.......: ChkFldType - Check that the replacement types are valid
*  Calling Samples...:
*  Parameter List....:
*  Created by........: Nadya Nosonovsky 06/22/2000 03:40:34 PM
*  Modified by.......: Nadya Nosonovsky 10/24/2002 11:35:02 AM
********************************************************************
local theType, theFld, llReturn, lnOption, lcTest
lnOption = thisform.GlobOpt.value
thisform.lOtherError = .f.

do case

case m.lnOption = 1 && Replace with constant

	theFld=thisform.txtReplaceVal.value
	theType=type('theFld')

	if m.theFld = "Clear Value"
		theFld = ""
	endif

case m.lnOption = 2 && Replace with field/combination of fields

	theFld=thisform.edtReplaceFld.value
	theType=type(m.theFld)
        * Suggestion from Tracy Holzer
	if m.theType = "U" and "(" $ m.theFld && VFP doesn't recognize functions correctly
		lcTest = &theFld
		theType=type("m.lcTest")
	endif

case m.lnOption = 3 && Swap

	theFld=thisform.SwapFld
	theType=type(m.theFld)
endcase

if thisform.lOtherError
	llReturn = .f.
else
	if empty(m.theFld) or thisform.CompareTypes(m.theType,thisform.cFieldType)
		llReturn = not thisform.lOtherError
	else
		llReturn = .f.
	endif
endif

return m.llReturn && and not thisform.lOtherError
E.g. I have Error method for the form already. I used macro, because I don't know in advance (expression may become very complicated and exceed 255 evaluate function limit).

It seems to work well.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform