AnsweredAssumed Answered

set user input decimal places

Question asked by Arlene Garfield on Oct 1, 2019
Latest reply on Oct 1, 2019 by Alex Burnett

I want the user input to be round to 1 decimal place.  Currently it is rounding to next whole number.

System option on Part is set to

Length: .12

Mass: .1

Under customer properties the field I have user input to are set to property type NUMBER

 

It seems to me it should be an easy fix but I have get to get it.

 

(In total the user is putting in 5 inputs but I am pasting the code for just 1 for this answer.)

It should be noted that the input are being pulled form custom properties and being used in equations.  I want it this way because we have tab fields set up where the user can go ahead and change just one or two value instead of running the whole macro again.

 

Other then the rounding issue the Macro and equations work perfect.

 

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swCustPropMgr As SldWorks.CustomPropertyManager

'Gets and sets the User input for Overall Tool Width
Dim UTWNumber As Integer

UTWNumber = InputBox("Specify Overall Tool Width")
Dim UTW As Integer
UTW = CDbl(UTWNumber)
MsgBox UTW

Dim TW As Long
Dim TWBool As Boolean
Dim WPropValues As String
Dim WResolved As String

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension

Set swCustProp = swModelDocExt.CustomPropertyManager("")


TW = swCustProp.Add3("Tool Side Width", swCustomInfoDouble, UTW, swCustomPropertyReplaceValue)

TWBool = swCustProp.Get4("Tool Side Width", False, WPropValues, WResolved)
   Debug.Print "Value: " & WPropValues
   Debug.Print "Evaluated value: " & WResolved
   Debug.Print "Up-to-date data: " & TWINT

MsgBox ("Equation Value have been updated" & vbCrLf & _
"Tool Width = " & WResolved)

Set swApp = Application.SldWorks
End Sub

Outcomes