Logical sort order in listbox

Discussion in 'AutoCAD' started by TomV, Feb 23, 2005.

  1. TomV

    TomV Guest

    Any ideas on how to make the following list of items:

    OP1
    OP10
    OP11
    OP2
    SCR

    sort as:

    OP1
    OP2
    OP10
    OP11
    SCR

    in a listbox?

    I want all of the digits in the string to be used in the sort, not digit by digit.

    Should I break up the text characters vs digits and then use the Format function:

    Format("1", "0#")
    Format("2", "0#")
    Format("10", "0#")

    Or, how about regular expressions? I think I could do this rather easily with Perl regular expressions, but I'm not sure if the VBA equivalent can do this.

    I'm thinking others have already tackled this issue and may have a solution.

    Thanks.
     
    TomV, Feb 23, 2005
    #1
  2. TomV

    Ed Jobe Guest

    Its always been a problem, e.g. even with filenames in a folder Windows will
    sort them that way. I use names like: OP01, OP10. If you don't want to
    compare char-by-char, but numerical value, then you will have to break up
    the string like you suggested. You can use the Right() function to get at
    "numerical" portion.

    --
    ----
    Ed
    ----
    with Perl regular expressions, but I'm not sure if the VBA equivalent can do
    this.
     
    Ed Jobe, Feb 23, 2005
    #2
  3. TomV

    Oberer Guest

    As Ed mentioned, you may have to start from the right and use the IsNumeric test to see where the number stops
     
    Oberer, Feb 23, 2005
    #3
  4. TomV

    TomV Guest

    Thanks guys.
     
    TomV, Feb 24, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.