Jump to content

VB Sorts text screen ditto text block in


Recommended Posts


in autocad block 4 line TXT

TXT1 (handle # 3)

TXT2 (handle # 2)

TXT3 (handle No. 4)

TXT4 (handle # 1)


When I recuper the string in a combobox it puts me in the order of handle


I then I want in the order of the line screen TXT1,2,3,4


Thank you for your help



Dans le bloc autocad 4 lignes de TXT

TXT1 (handle N°3)

TXT2 (handle N°2)

TXT3 (handle N°4)

TXT4 (handle N°1)


Quand je recupere le string dans une combobox il me le met dans l'ordre du handle =>Ligne 4,2,1,3

alors que je je veux dans l'ordre de l'écran ligne 1,2,3,4


Merci pour votre aide


Public Sub LireTxt()

Dim objBloc As AcadBlock

Dim objEnt As AcadEntity

Dim objEntTxT As as AcadText


ThisDrawing.Utility.GetEntity objBlocRef, Pt1, "Sélectionnez le bloc à modifier :"

Set objBloc = ThisDrawing.Blocks(objBlocRef.Name)


For Each objEnt In objBloc

If objEnt.ObjectName = "AcDbText" Then

ListBoxTxt.AddItem objEntTxT.textString




End Sub

Link to comment
Share on other sites

Try this code, then rewrite this example to your needs:


Option Explicit
Option Compare Binary 'working with 'Option Compare Text' as well
  Sub BubbleSort(arr As Variant, Optional descending As Boolean, Optional numEls As Variant)
          ' Bubble Sort an array of any type
          ' Author: The VB2TheMax Team
          ' BubbleSort is especially convenient with small  arrays (1,000
          ' items or fewer) or with arrays that are  already almost sorted
          ' NUMELS is the index of the last item to be sorted, and is
          ' useful if the array is only partially filled.
          ' Works with any kind of array, except UDTs and fixed -Length
          ' strings, and including objects if your are sorting on their
          ' default property. String are sorted in case-sensitive mode.
          ' You can write faster procedures if you modify the first two lines
          ' to account for a specific data type, eg.
           'Sub BubbleSortS(arr() As Single, Optional descending As Boolean, Optional numEls As Variant)
          ' Dim value As Single
          Dim Value As Variant
          Dim Index As Long
          Dim firstItem As Long
          Dim indexLimit As Long, lastSwap As Long
          ' account for optional arguments
          If IsMissing(numEls) Then numEls = UBound(arr)
          firstItem = LBound(arr)
          lastSwap = numEls
          indexLimit = lastSwap - 1
          lastSwap = 0
          For Index = firstItem To indexLimit
          Value = arr(Index)
          If (Value > arr(Index + 1)) Xor descending Then
          ' if the items are not in order, swap them
          arr(Index) = arr(Index + 1)
          arr(Index + 1) = Value
          lastSwap = Index
          End If
          Loop While lastSwap
          End Sub
         Sub testSort()
         Dim strText As String
         Dim Items(3) As Variant
         Dim i
         Items(0) = "handle N°3"
         Items(1) = "handle N°1"
         Items(2) = "handle N°2"
         Items(3) = "handle N°4"
         'Sort array by descending:
         BubbleSort Items, False
         For i = LBound(Items) To UBound(Items)
         Debug.Print Items(i)
         Next i
         End Sub

Link to comment
Share on other sites

fine sorting sub fixo.


I also posted a possible solution to acad386bis problem at http://forums.autodesk.com/t5/Visual-Basic-Customization/VBA-tri-le-TXT-in-bloc-dans-listbox-idem-bloc-%C3%A9cran/td-p/4855179

where I used a sorting sub managing a matrix instead of an array, developed for a more general use.

but I'll certainly enhance that sub using ideas coming from yours




Link to comment
Share on other sites

RICVBA thank you!





So cool this forum ...

The code is really pretty, it's been fun to read.

It was not so complicated to final

thank you again

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...