Message 1 of 2
vba calculate length of line selected help

Not applicable
03-03-2005
06:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
'------------------------------------------------------------------------------------
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
'------------------------------------------------------------------------------------