vba calculate length of line selected help

vba calculate length of line selected help

Anonymous
Not applicable
308 Views
1 Reply
Message 1 of 2

vba calculate length of line selected help

Anonymous
Not applicable
I have avba project i am working on which asks the user to select apolyline on the drawing. The code then gets the length of the line but rturns to abiut 6 decimal places.
Question 1.
How do i get it to return the length to 2 decimal places only?
Question 2.
If the user selects anumber (ie 2, 3, 4 etc) from a combobox on a user form in the project, how do i get the length of the line multiplied by the selected number?
I have listed the code i have at present below. I think that is all.
Regards JohnB
'------------------------------------------------------------------------------------

Public Sub AddTendon()
Dim intFilterType(0 To 0) As Integer
Dim varFilterData(0 To 0) As Variant
Dim objSelectionSet As AcadSelectionSet

For Each objSelectionSet In ThisDrawing.SelectionSets
If objSelectionSet.Name = "AddTendon" Then
objSelectionSet.Delete
Exit For
End If
Next objSelectionSet

Set objSelectionSet = ThisDrawing.SelectionSets.Add("AddTendon")

ThisDrawing.Utility.prompt "Select a tendon..." & vbCrLf

intFilterType(0) = 0
varFilterData(0) = "LWPOLYLINE"
objSelectionSet.SelectOnScreen intFilterType, varFilterData

If objSelectionSet.Count > 0 Then
strTendonLength = CalcTendonLength(objSelectionSet(0))
frmAddTendon.Show
Else
Exit Sub
End If
End Sub
'------------------------------------------------------------------------------------

Public Function CalcTendonLength(objPolyLine As AcadLWPolyline) As Double
Dim varEntities As Variant
Dim dblLength As Double
Dim intIndex As Integer

dblLength = 0#

varEntities = objPolyLine.Explode
For intIndex = LBound(varEntities) To UBound(varEntities)
If TypeOf varEntities(intIndex) Is AcadLine Then
dblLength = dblLength + varEntities(intIndex).Length
ElseIf TypeOf varEntities(intIndex) Is AcadArc Then
dblLength = dblLength + varEntities(intIndex).ArcLength
End If
varEntities(intIndex).Delete
Next intIndex

CalcTendonLength = dblLength
End Function

'------------------------------------------------------------------------------------
0 Likes
309 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
"johnbortoli" wrote in message news:24750915.1109903967538.JavaMail.jive@jiveforum1.autodesk.com... > I have avba project i am working on which asks the user to select apolyline on the drawing. The code then gets the length of the line but rturns to abiut 6 decimal places. > Question 1. > How do i get it to return the length to 2 decimal places only? Debug.Print Round(25.345243985744, 2) or if you're dealing with strings look at the Format function hth > Question 2. > If the user selects anumber (ie 2, 3, 4 etc) from a combobox on a user form in the project, how do i get the length of the line multiplied by the selected number? now I'm not sure what you're exactly asking cause I'm sure you know... dLen = 25.25 lNum = 4 dRes = dLen * lNum so I think i'm missing something in your question... Mark
0 Likes