VBA SolidWorks Convert String Value

Here I have a small problem, I get values from the solder parts list to send them to the custom properties. I use; "SW-Sidewall width of tôle@@@Sheet<1>@C000-00-MS-001. SLDPRT"

The value returned is unstable, it does not follow the unit format configured in the document properties. It automatically truncates the 0s on the right if it has any, even if the option not to delete them is checked. So I thought of a solution. Via a macro go get the value, transform it to 3 decimal places and finally return it in the custom properties. The problem is that I am able to go and get this value and send it back but I don't know how to transform it into a value to 3 decimal places, could someone help me.

Thank you

    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swCustPropMgr As SldWorks.CustomPropertyManager
    Dim textexp As String
    Dim valout As String
    Dim retVal As Double
    

    Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")


        swCustPropMgr.Get2 "teste", textexp, valout
        
        retVal = swCustPropMgr.Delete2("teste")
        retVal = swCustPropMgr.Add2("teste", swCustomInfoText, valout)
        
        MsgBox "teste" & " = " & valout

End Sub

 

Hello

You will find a whole lot of information on how to manipulate strings in VBA ICI.

Kind regards

1 Like

Good evening

By the way:

MsgBox "teste" & " = " & valout

 

... can, and should be, simplified by:

MsgBox "teste = " & valout

 

Cdt

1 Like