2 Replies Latest reply on Feb 15, 2016 2:03 AM by None None

    Need to make a error.

    None None

       

       

      If one of these \ / " * ? < > | characters being used in sDescription  then.

       

      Call swApp.SendMsgToUser("You cannot use these characters in the description: \ / " * ? < > |.")

      How can i make this work?

       

       

       

      --------------------------------------------------------------------------------

      Sub CreatePNG()

      Dim FileName        As String

      Dim sDescription    As String

      Dim sRevision       As String

       

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc

       

      sDescription = Part.CustomInfo("description")

      sRevision = Part.CustomInfo("revision")

       

      FileName = Part.GetPathName

       

      If (FileName = "") Then

          Call swApp.SendMsgToUser("No file saved. Please save part or assembly file prior to running macro.")

      Else

          If (sDescription = "") Or (sRevision = "") Then

              Call swApp.SendMsgToUser("Please fill in the description/revision.")

          Else

              FileName = Left(FileName, Len(FileName) - 7) & sRevision & " - " & sDescription

         

              Me.LabelStatus.Caption = "Creating .PNG File"

              FileName = FileName & ".png"

      ------------------------------------------------------------------------------------------------------------------------------------

       

       

       

       

       


        • Re: Need to make a error.
          Matthew Cempa

          Dim swApp As SldWorks.SldWorks
          Sub main()
              Dim sBadChars As String
              Dim sFileName As String
              Dim Chars As Variant
              Dim i As Integer
              Dim p As Integer
             
              sBadChars = "\ / "" * ? < > |"
              sFileName = "test\file.png"
              Set swApp = Application.SldWorks
             
              Chars = Split(sBadChars)
              For i = 0 To UBound(Chars)
                  If InStr(sFileName, Chars(i)) <> 0 Then
                      swApp.SendMsgToUser (sBadChars & " not allowed")
                  End If
              Next i

          End Sub