FormatResult method

Microsoft Visio Developer Reference

FormatResult method

       

Formats a string or number into a string according to a format picture, using specified units for scaling and formatting.

Version added

4.5

Syntax

stringRet = object.FormatResult(stringOrNumber, unitsIn, unitsOut, format)

stringRet

String. The evaluated result formatted according to format and unitsOut.

object

Required. An expression that returns an Application object.

stringOrNumber

Required Variant. String or number to be formatted; can be passed as a string, floating point number, or integer.

unitsIn

Required Variant. Measurement units to attribute to stringOrNumber.

unitsOut

Required Variant. Measurement units to express the result in.

format

Required String. Picture of what the result string should look like.

Remarks

If passed as a string, stringOrNumber might be the formula or prospective formula of a cell, or the result or prospective result of a cell expressed as a string. The FormatResult method evaluates the string and formats the result. Because the string is being evaluated outside the context of being the formula of a particular cell, the FormatResult method returns an error if the string contains any cell references.

Possible values for stringOrNumber include:

1.7

3

"2.5"

"4.1 cm"

"12 ft - 17 in + (12 cm / SQRT(7))"

The unitsIn and unitsOut arguments can be strings such as "inches", "inch", "in.", or "i". Strings may be used for all supported Visio units such as centimeters, meters, miles, and so on. You can also use any of the unit constants declared by the Visio type library in VisUnitCodes. A list of valid units is also included in About units of measure.

If stringOrNumber is a string, unitsIn specifies how to interpret the evaluated result and is only used if the result is a scalar. For example, the expression "4 * 5 cm" evaluates to 20 cm, which is not a scalar so unitsIn is ignored. The expression "4 * 5" evaluates to 20 which is a scalar and is interpreted using the specified unitsIn.

The unitsOut argument specifies the units in which the returned string should be expressed. If you want the results expressed in the same units as the evaluated expression, pass "NOCAST" or visNoCast.

format is a string that specifies a template or picture of the string produced by the FormatResult method. For details, see the FORMAT function. A few of the possibilities are:

# : Ouput a single digit, but not if it's a leading or trailing 0.

0 : Output a single digit, even if it is a leading or trailing 0.

. : Decimal placeholder.

, : Thousands separator.

"text" or 'text' : Output enclosed text as is.

\c : Output the character c.

Examples

Click to show or hide information.Where a string is specified

Debug.Print Application.FormatResult("0.5 * 2", "ft", "ft", "#.00 u")    >>> 1.00 ft.
Debug.Print Application.FormatResult("0.5 * 2", "ft", "in", "#.00 u")    >>> 12.00 in.
Debug.Print Application.FormatResult("1 cm", "ft", "in", "#.00 u")    >>> .39 in.
Debug.Print Application.FormatResult("1 cm", "ft", "NOCAST", "#.00 u")    >>> 1.00 cm.
Debug.Print Application.FormatResult("1 cm", "ft", "", "0.00 u")    >>> 0.39
Debug.Print Application.FormatResult("1 sq. ft. * 2", "in^2", "cm^2", "0.00 u")    >>> 1858.06 sq. cm.
Debug.Print Application.FormatResult("1 cm", "ft", "bozo", "#.00 u")    >>> exception: Bad measurement unit.

Click to show or hide information.Where a number is specified

Debug.Print Application.FormatResult(1, "ft", "ft", "#.00 u")    >>> 1.00 ft.
Debug.Print Application.FormatResult(1, "ft", "in", "#.00 u")    >>> 12.00 in.
Debug.Print Application.FormatResult(1.0, "in", "ft", "#.00 u")    >>> .08 ft.
Debug.Print Application.FormatResult(1.0, visFeet, "", "#.00 u")    >>> 12.00 
Debug.Print Application.FormatResult(1, "bozo", "in", "#.00 u")    >>> exception: Bad measurement unit.