Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Application.ConvertResult Method (Visio)

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

Version Information

Version Added: Visio 4.5


expression .ConvertResult(StringOrNumber, UnitsIn, UnitsOut)

expression A variable that represents an Application object.


Name Required/Optional Data Type Description




String or number to be converted; can be a string, floating point number, or integer.




Measurement units to attribute to StringOrNumber.




Measurement units to express the result in.

Return Value



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:




"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 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 vsoApplication.ConvertResult("0.5 * 2", "ft", "ft") >>> 1.0 
Debug.Print vsoApplication.ConvertResult("0.5 * 2", "ft", "in") >>> 12.0 
Debug.Print vsoApplication.ConvertResult("1 cm", "ft", "in") >>> 0.39 
Debug.Print vsoApplication.ConvertResult("1 cm", "ft", "NOCAST") >>> 1.0 
Debug.Print vsoApplication.ConvertResult("1 cm", "ft", "") >>> 0.39 
Debug.Print vsoApplication.ConvertResult("1 cm", "ft", "bozo") >>> exception: Bad measurement unit. 

Examples where number is specified:

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


The following macro shows how to use the ConvertResult method to report the distance between two shapes in centimeters, feet, yards, and miles. To run this macro, you must have two shapes selected on your page.

Sub ConvertResult_Example() 
 Dim vsoApplication As Visio.Application 
 Dim vsoWindow As Visio.Window 
 Dim vsoSelection As Visio.Selection 
 Dim vsoShape1 As Visio.Shape 
 Dim vsoShape2 As Visio.Shape 
 Dim dblPinX1 As Double 
 Dim dblPinY1 As Double 
 Dim dblPinX2 As Double 
 Dim dblPinY2 As Double 
 Dim dblPinX1in As Double 
 Dim dblPinY1in As Double 
 Dim dblPinX2in As Double 
 Dim dblPinY2in As Double 
 Dim lngCount As Long 
 Dim dblDistance As Double 
 Dim dblDistanceX As Double 
 Dim dblDistanceY As Double 
 Dim dblResult(4) As Double 
 Dim strUnit As String 
 Set vsoApplication = Visio.Application 
 Set vsoWindow = vsoApplication.ActiveWindow 
 'Drawing page must be active window 
 If vsoWindow.Type = 1 Then 
 Set vsoSelection = vsoWindow.Selection 
 lngCount = vsoSelection.Count 
 'Exactly two shapes should be selected 
 If lngCount <> 2 Then 
 MsgBox "A total of " & lngCount & " shapes are " _ 
 & "selected. Please select two shapes and try " _ 
 & "again", 0 
 Set vsoShape1 = vsoSelection.Item(1) 
 Set vsoShape2 = vsoSelection.Item(2) 
 'Pass the Visio Automation constant for inches (visInches, which is defined as 65) to the Result method to force units to inches 
 dblPinX1in = vsoShape1.Cells("PinX").Result(65) 
 dblPinY1in = vsoShape1.Cells("PinY").Result(65) 
 dblPinX2in = vsoShape2.Cells("PinX").Result(65) 
 dblPinY2in = vsoShape2.Cells("PinY").Result(65) 
 dblDistance = Sqr((dblPinX2in - dblPinX1in) ^ 2 + _ 
 (dblPinY2in - dblPinY1in) ^ 2) 
 'Convert distances from inches to centimeters, feet, yards, and miles 
 dblResult(1) = vsoApplication.ConvertResult(dblDistance, "in", "cm") 
 dblResult(2) = vsoApplication.ConvertResult(dblDistance, "in", "ft") 
 dblResult(3) = vsoApplication.ConvertResult(dblDistance, "in", "yd") 
 dblResult(4) = vsoApplication.ConvertResult(dblDistance, "in", "mi") 
 'Display results 
 MsgBox dblResult(1) & " centimeters; " & dblResult(2) & " feet; " & _ 
 dblResult(3) & " ;yards; " & dblResult(4) & " miles ", 0 
 End If 
 MsgBox "The drawing page must be active.", 0 
 End If 
End Sub 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.