Macro recording

Hi all

I don't know if this is the right place to ask this question but I know that there are some who touch the Vba SW well. This would be to have some explanations because every time I record a macro I ask myself these questions: Here is a saved macro used to reconstruct a file:

               Dim swApp As Object
               Dim Part As Object
               Dim boolstatus As Boolean
               Dim longstatus As Long, longwarnings As Long
Sub main()
               Set swApp = _
               Application.SldWorks
               Set Part = swApp.ActiveDoc
               boolstatus = Part.EditRebuild3()
End Sub

I would like to know why SW always creates the "longstatus" and "longwarning" variables when it almost never uses them? Just in case? What could they be used for please?
In addition there is this variable of the type Boolean, why is it created please? And why is this type of varaible used to carry out this reconstruction action?

Thank you for your answers which will enlighten me for the coding of my macro:)

Have a nice day

longqtatus and longwarning are used to recover error codes if there are any in your example you can delete it because they are not used in the code

for boolstatus it's specific to SW and I wouldn't really define its stakes but you have to leave it :/

2 Likes

These are usually variables used to retrieve errors. For example on

   boolstatus = Part.EditRebuild3()

You can do a test like this:

   If boolstatus Then
      Debug.print "Function Successful"
  else
      Debug.print "Function Failed"
   Endif

But personally I almost never use them, I delete them all the time. What I advise you to do when you have recorded a macro:

   Set swApp = _
               Application.SldWorks

  -> Ability to put on a single line

   Set swApp = Application.SldWorks

----

               Dim swApp As Object
               Dim Part As Object

Specify the types to have the list of available functions

               Dim swApp As SldWorks.SldWorks
               Dim Part As SldWorks.ModelDoc2

 

2 Likes