3 Replies Latest reply on Nov 16, 2015 4:02 PM by Matthew aDAMS

    EPDM Set Revision:  Str to Int. to get revision counter number

    Matthew aDAMS

      Hi guys,

       

      I have run into a little bit of an issue today that I am not sure how to tackle.  I have been using the SolidWorks API example: Set Revisions (Visual Basic) to manually set revisions on some older files that failed during migration..  Everything was working great until today, I need to set a manually revision on an older document that is "AD". This revision is support by my revision schema but the API is using Asc(RevisionProp.ToUpper()) - Asc("A") + 1 (roughly line 218 of sample code) to get the revision number.  This all makes since but I can not figure out how to get this to work for a double letter.  Asc or AscW only takes the first character that it come to.  Basically I need to convert a double letter string to an integer. I'm not sure if an IF statement that would calculate differently if the string count is equal to 2 would work or what that formula would like.

       

      Has anyone run into this before?  I don't really want to run this though a workflow as that seems to be the hard way of doing things.

       

      Thanks in advance! 

       

      Matthew

        • Re: EPDM Set Revision:  Str to Int. to get revision counter number
          Jim Sculley

          Wow, what a kludgy way to do that.  I can't believe SW is using ASCII character codes to do this.  Very brittle, as you have discovered.

           

          Well, rather than reinvent the wheel, you can use their approach with some adjustments.  If your revision string is more than one character you can figure out the revision for the first character and multiply it by 26.  Then add the revision for the second character.  It is basically base 26 math as opposed to base 10:

          A=1

          B=2

          C=3

          ...

          ...

          ...

          Z=26

          AA=27 (26 * 1 + 1)

          AB=28 (26 * 1 + 2)

          AC=29 (26 * 1 +3)

          AD=30 (26 * 1 + 4)

          ...

          ...

          ...

          AZ=52 (26 * 1 + 26)

          BA=53 (26 * 2 + 1)

           

           

          Jim S.

            • Re: EPDM Set Revision:  Str to Int. to get revision counter number
              Matthew aDAMS

              Jim,

               

              I took your advice but I can't seam to get the code to work.  This is my first attempt at using math inside VB.  I'm getting a Conversion from string "A" to type 'Double' is not valid on the line shown in BOLD below.  I have tried a couple of different things and done some googling but I am unsure what the issue is.

               

                             'This section working without issue

                          If RevisionProp.Length = "1" Then

                              Dim RevInt As Long

                              RevInt = _

                                 Asc(RevisionProp.ToUpper()) - Asc("A") + 1

                              RevCounters(0).mlCounter = RevInt

               

                          ElseIf RevisionProp.Length = "2" Then

                              Dim RevInt As Long

                              Dim RevStr1 As String

                              Dim RevStr2 As String

               

                              RevStr1 = Mid(RevisionProp.ToUpper, 1, 1)  'Gets first letter as string

                              RevStr2 = Mid(RevisionProp.ToUpper, 2, 1)  'Gets second letter as string

                              RevInt = Asc(RevStr1 - Asc("A") + 1) * 26 + Asc(RevStr2 - Asc("A") + 1)

                              RevCounters(0).mlCounter = RevInt

                          End If

                • Re: EPDM Set Revision:  Str to Int. to get revision counter number
                  Matthew aDAMS

                  I missed a "("

                   

                              If RevisionProp.Length = "1" Then

                                  Dim RevInt As Long

                                  RevInt = _

                                     Asc(RevisionProp.ToUpper()) - Asc("A") + 1

                                  RevCounters(0).mlCounter = RevInt

                              ElseIf RevisionProp.Length = "2" Then

                                  Dim RevInt As Long

                                  Dim RevStr1 As String

                                  Dim RevStr2 As String

                                  RevStr1 = Mid(RevisionProp.ToUpper, 1, 1)

                                  RevStr2 = Mid(RevisionProp.ToUpper, 2, 1)

                                  RevInt = (Asc(RevStr1) - Asc("A") + 1) * 26 + Asc(RevStr2) - Asc("A") + 1

                                  RevCounters(0).mlCounter = RevInt

                              End If