Description

Converts value(s) from a variant into a character string.

Return Type

A McObject object.  

Syntax

object.McToText (varToText, [varFormat])

The McToText Method syntax has these parts:

PartDescription
objectAn expression evaluating to an object of type McOMGlobal.
varToTextRequired. A Variant value.

A value or array of values to render into text form. May be a scalar or array of any numeric or text Variant type. It may also be an McObject instance of a numeric or text McObject type. If the varToText source is already a String or array of strings, then any varFormat argument is ignored and

varFormatOptional. A Variant value.

An array of up to five formating strings, as follows

    0   C style format string (ie. “c”.

    1   Before all string to be placed in front of converted values

    2   String to be placed between each converted value within a “row”. In
    the case of strings, this is placed between each character.

    3   After all string to be placed after all converted values

    4   String to be placed between each “row”, or in the case of string
    sources, between each string.

If only one varFormat string is given as (rather than an array of strings), then the string is interpreted as the formatting string for each value (element 0 in the above table).

If missing, use the default format string for this data type (see notes), placing a space between multiple numeric values, “\r\n” between rows and with nothing before or after the converted values.

ppimcobjResult : A mcobjTypeCHAR containing the formatted text.

Remarks

This function is is analagous to the C language 'sprintf' function; its purpose is to convert numerical data stored in binary form in a Variant into readable text returned in a mcobjTypeCHAR.

Only the first argument, the Variant to convert, is required. In this default formating case you will get a reasonable default conversion with a compact representation of each number. For numeric sources, if the array length to be converted is greater than one, then each value in the array is separated by one space. No leading or trailing space appears, and each “row” of two (or higher) dimensional arrays is separated by a carriage-return/line-feed, vbCrlf, pair. For String scalar or array sources, the default is to separate each string after the first by a vbCrlf, thus placing each string on its own line.

The default will work for most cases, but substantial flexibilty in the output format of the Variant to be converted is supported. The conversion format for each value can be specified (using C's sprintf formating rules). You can also specify strings to be to be placed before and/or after all numbers (or source text strings), a string to be place between multiple values of a vector (or between individual characters of source text strings) and a string to be placed between the “rows” of multi-dimensional vectors (or between succesive strings in a source array of them).

When converting scalar values or user-defined-types to text, consider using McSprintf instead of McToText. McSprintf can deal with an arbitrary number of arguments and allows you to specify a formatting string for all arguments together.

If the number of elements in the varFormat array is less than five or if any element is a blank string, then a default is used for the missing rows. The default is to separate numeric array elements by spaces and to place a line-break between the “rows” of 2-D arrays or arrays of strings.

If varFormat is given, the user is responsible for matching the each-value formatting string (element 0 of varFormat) to the Variant data type. Default formats for each basic data type (and types derived therefrom) are: CHAR “c”, LONG “d”, SHORT “hd”, BYTE “d”, FLOAT or REAL “%g”.