4 Replies Latest reply on May 22, 2014 3:50 PM by Michael Ferraro

    What is this Code?

    Michael Ferraro

      Hello All,

       

      I am in the process of attempting to create a macro and I have taken another macro with a similar function and am attempting to tweak it as necessary.

       

      Could anyone tell me what the following few lines of code are actually doing?

       

      ~~~~~

      ...

      Dim swDocTypeLong As Long

       

      ext = UCase$(ext)

      swDocTypeLong = Switch(ext = ".SLDDRW", swDocDRAWING, True, -1)

       

      If swDocTypeLong = -1 Then

      Exit Sub

      ...

      ~~~~~

       

      Thank you very much!

       

      Pencil

        • Re: What is this Code?
          Patrick O'Hern

          ext = UCase$(ext)  - I'm assuming "ext" has been defined elsewhere in the code to be the file extension.  This line is setting it to be uppercase

           

          swDocTypeLong = Switch(ext = ".SLDDRW", swDocDRAWING, True, -1) - This is checking to see if the file extension is for a Drawing.  If it is, then "swDocTypeLong" is set to match a drawing document, otherwise it is set to "-1".

           

          If swDocTypeLong = -1 Then  -  This is checking to see if "swDocTypeLong" was set to "-1" in the previous line

          Exit Sub  - This exits the sub if the previous line was true

           

           

          You could do the same thing by using:

           

          If UCase$(ext) = ".SLDDRW" Then

               swDocTypeLong = swDocDrawing

          Else

               swDocTypeLong = -1

               Exit Sub

          End If

           

          Or you could simplify it even more if swDocTypeLong is only being used in this sub:

           

          If Not UCase$(ext) = ".SLDDRW" Then

               Exit Sub

          End If