ConvertResult method

Microsoft Visio Developer Reference

ConvertResult method

       

Converts a string or number into an equivalent number in different measurement units.

Version added

4.5

Syntax

retVal = object.ConvertResult(StringOrNumber, unitsIn, unitsOut)

retVal

Double. The result of the conversion.

object

Required. An expression that returns an Application object.

StringOrNumber

Required Variant. String or number to be converted; can be 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.

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 ConvertResult method evaluates the string and converts the result into the units designated by unitsOut. The ConvertResult 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 units constants declared by the Visio type library in VisUnitCodes. A list of valid units is also listed in About units of measure.

If StringOrNumber is a floating point number or integer, unitsIn declares what unit of measure the ConvertResult method should construe the number to be. Pass "" to indicate internal Visio units.

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 in what units the returned number should be expressed. If you want the results expressed in the same units as the evaluated expression, pass "NOCAST" or visNoCast.

Examples where string is specified:

Debug.Print application.ConvertResult("0.5 * 2", "ft", "ft")    >>> 1.0
Debug.Print application.ConvertResult("0.5 * 2", "ft", "in")    >>> 12.0
Debug.Print application.ConvertResult("1 cm", "ft", "in")    >>> 0.39
Debug.Print application.ConvertResult("1 cm", "ft", "NOCAST")    >>> 1.0
Debug.Print application.ConvertResult("1 cm", "ft", "")    >>> 0.39
Debug.Print application.ConvertResult("1 cm", "ft", "bozo")    >>> exception: Bad measurement unit.

Examples where number is specified:

Debug.Print application.ConvertResult(1, "ft", "ft")    >>> 1
Debug.Print application.ConvertResult(1, "ft", "in")    >>> 12
Debug.Print application.ConvertResult(1.0, "in", "ft")    >>> 8.33333333333333E-02 
Debug.Print application.ConvertResult(1.0, visFeet, "")    >>> 12
Debug.Print application.ConvertResult(1, "bozo", "in")    >>> exception: Bad measurement unit.