Fausto,
The problem is if uMyVar = "5" the procedure returns N instead of C.
I have solved the problem by checking to see if the contents of a C variable are a valid VFP variable, field, property name before checking the type of the contents of the variable.
lcType = TYPE( 'tuValue' )
IF lcType = 'C' AND ( LEFT( tuValue, 1 ) = "_" OR ISALPHA( tuValue ) ) AND TYPE( tuValue ) # 'U'
lcType = TYPE( tuValue )
tuValue = EVAL( tuValue )
ENDIF
Thanks for the help.
>Shane,
>
>I've got confused. I tested the code with the original examples you gave and got it working apparently well ...
>
>
>>Fausto,
>>
>>This does not work if uMyVar equals "3", ".T." or "{^2001/01/01}" then TYPE("&uMyVar") or TYPE(uMyVar) returns N, L or D instead of U. This is the problem that I have. It appears that TYPE tries to evaluate uMyVar then returns the type of the result.
>>
>>Any ideas,
>>
>>Shane
>>
>>
>>
>>>Hi Shane,
>>>
>>>Here is some code that does what you need:
>>>
>>>
>>>PROCEDURE cMyFunc
>>>PARAMETERS uMyVar
>>>LOCAL cReturnValue
>>>IF TYPE("uMyVar")="C" THEN
>>> IF TYPE("&uMyVar")="U" THEN
>>> *Means that the parameter came with a string
>>> *which has an <b>U</b>ndefined "inner" value,
>>> *so we consider it a simple string ("C")
>>> cReturnValue="C"
>>> ELSE
>>> *Here there is inner value!
>>> cReturnValue = TYPE("&uMyVar")
>>> ENDIF
>>>ELSE
>>> cReturnValue = TYPE("uMyVar")
>>>ENDIF
>>>RETURN cReturnValue
>>>ENDPROC
>>>
>>>
>>>Hope this helps to solve your problem!
>>>
>>>
>>>>I need a procedure that will accept one parameter. This parameter may contain the value I want or it may contain the name of a variable that contains the value that I want. Here are some examples.
>>>>
>>>>PROCEDURE cMyFunc( uMyVar )
>>>>... What code goes here?
>>>>RETURN cReturnValue
>>>>ENDPROC
>>>>
>>>>x = "test"
>>>>cMyFunc( x ) should return 'C'
>>>>
>>>>x = 5
>>>>cMyFunc( x ) should return 'N'
>>>>
>>>>x = "5"
>>>>cMyFunc( x ) should return 'C'
>>>>
>>>>x = .T.
>>>>y = "x"
>>>>cMyFunc( y ) should return 'L'
>>>>
>>>>How do I figure out if a character parameter contains the name of another variable?
>>>>
>>>>Any ideas?
Shane Murdoch