InvisibleApp.FormatResult Method
Visio Automation Reference |
Formats a string or number into a string according to a format picture. Uses specified units for scaling and formatting.
Version Information
Version Added: Visio 4.5
Syntax
expression.FormatResult(StringOrNumber, UnitsIn, UnitsOut, Format)
expression A variable that represents an InvisibleApp object.
Parameters
Name | Required/Optional | Data Type | Description |
---|---|---|---|
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. |
Return Value
String
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 Microsoft Office 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:
# : Output 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.
Example
Where a string is specified
Visual Basic for Applications |
---|
|
Where a number is specified
Visual Basic for Applications |
---|
|
The following macro shows how to use the FormatResult method to convert a value from centimeters to inches and display the result in a message box.
Visual Basic for Applications |
---|
|
See Also