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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if is a String

Status
Not open for further replies.

imox

Programmer
May 13, 2013
37
DE
Hello,

how can I check a variable if is a String? Normaly it is very simple but not in foxpro ;)

Thanks a lot ;)
 
I want cast all incomming type like date, integer some else to a string.
 
No, in VFP this is simple, too:

Code:
If Vartype(variable) = "C"
   ? "It's a string! It's a string!"
Endif

Each vartype has a letter, NUL is denoted with "X".
For other variable type see
There also is the TYPE() function, it differs from VARTYPE() in that you would need to pass in the name of the variable to check as string, eg TYPE("variable") is the same as VARTYPE(variable).

Bye, Olaf.
 
Ok thanks it works I only tried type() and I got something errors.
 
Well, what error? You have to put the name in quotation marks for TYPE, so TYPE() only accepts a string as paramters, a string containing the name of a variable or an expression evaluatable, and of course it returns the type the expression or variable has, not always "C". VarType() is more straight forward.

But you need neither of these two functions, because Transform() will turn everything into a string.

What do you need that for? To create a file with CSV output? Use COPY TO TYPE CSV instead.

Bye, Olaf.
 
I need it to write XML. I use TRANSFORM() but when I transform 0.0000000 then I get only 0 as string. It is possible do not cut anything?
 
when I transform 0.0000000 then I get only 0 as string. It is possible do not cut anything?

That is correct. If you want to get "0.0000000" as a string, you should use TRANSFORM(<your integer>, "9.9999999").

(But that's got nothing to do with XML.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike is right, more generally speaking lookup the reference section on Transform. STR() also is a specialised version of the conversion of numerical variable to string. Ther are others, eg DTOC() or TTOC(), for Date or Datetime to string conversion, Transform is just the core function handling all types, the special functions are slightly faster for each certain type.

In case XML creation, why reinvent the wheel? Eiter use Rick Strahls wwXML classlib or CURSORTOXML(), just to name two possible already existing solutions. You might also automate MSXML OLE classes.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top