2 Replies Latest reply on Nov 19, 2012 6:28 AM by Robert Harsa

    Sorting numbers

    Robert Harsa

      I wanted to sort my dimension to smallest number the largest number having a little trouble with doing the

      Ex. if the block is 5.000 x 2.000 x 1.500 I would like to 1.500 x 2.000 x 5.000 in custom properties

        • Re: Sorting numbers
          Artem Taturevych

          It's not completely clear what input do you have. I assume you have a string so you can use the following function:

           

          Sub main()

           

           

              Debug.Print SortNumbers("5.000 x 2.000 x 1.500")

             

          End Sub

           

           

          Function SortNumbers(inputStr As String) As String

             

              Dim vNumbers As Variant

              vNumbers = Split(inputStr, "x")

             

              'bubble sort

              Dim i As Integer

              Dim j As Integer

              Dim temp As String

                 

              For i = UBound(vNumbers) To 1 Step -1

                  For j = 0 To i - 1

                      If CDbl(vNumbers(j)) > CDbl(vNumbers(j + 1)) Then

                          temp = vNumbers(j)

                          vNumbers(j) = vNumbers(j + 1)

                          vNumbers(j + 1) = temp

                      End If

                  Next

              Next

             

              For i = 0 To UBound(vNumbers)

                  SortNumbers = SortNumbers & Trim(vNumbers(i))

                  If i <> UBound(vNumbers) Then

                      SortNumbers = SortNumbers & " x "

                  End If

              Next

             

          End Function

          ______________________

          Regards,

          Artem Taturevych

          Application Engineer at Intercad

          http://intercad.com.au/

          Tel: +61 2 9454 4444