Transform()

This function formats a numeric or character expression using the picture and function clauses available with the Format and InputMask properties.

Usage

cRetVal = TRANSFORM( uExpression [, cFormat ] )

Parameter

Value

Meaning

eExpression

Any field types except Picture and General

Expression to be transformed.

cFormat

Character

Format codes, preceded by the @ symbol, and InputMask codes.

 

Omitted
(VFP 6 and later)

Transforms any data type sent to it with a default format, specified in the Help file.

cRetVal

Character

A character string resulting from the formatting.


TRANSFORM() can be a very handy way to express a special coding system—such as currency, ID numbers or stock numbers—with a defined picture, without having to store the formatting with each field. In addition, TRANSFORM() is useful as a generic translator of any type of data, as it accepts all but General and Picture fields as expressions, and always returns a character field.

Any attempt to TRANSFORM the contents of a Memo field by specifying a format code results in a return of the string "Memo," a useless result as far as we are concerned. Apply ALLTRIM() to the memo field to get the result you want. Omitting the format code in VFP 6 or later returns the same result as ALLTRIM()—but what's the point?


Example

cRetVal = TRANSFORM("6175551212", "@R (999) 999-9999" )
* Returns "(617) 555-1212"
? TRANSFORM(12345,"@B $$9,999,999")
* Left-justified, floating $ sign: "$12,345"
? TRANSFORM(date(),"@E")  
* Returns string of format DD/MM/YY
? TRANSFORM(PRINTSTATUS(),"Y")  && Displays "Y" or "N"
 
* The hexadecimal display was introduced in VFP 5.0:
? TRANSFORM(12345, "@0")  
* "at zero" yields "0x00003039" 
 
* Assume that Notes is a memo field
? TRANSFORM(Notes, "@!")  && Returns "Memo" - Doh!
? TRANSFORM(ALLTRIM(Notes), "@!") 
* Returns the memo all caps
? TRANSFORM(Notes)
* In VFP 6 & 7, returns the memo value

See Also

DToC(), DynamicInputMask, InputMask, Format, Str(), TToC(), Val()


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .