Results 1 to 12 of 12
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    WordBasic.SortArray (All VBA versions of Word)

    How is wordBasic.SortArray supposed to sort strings?

    I'm puzzled by the failure to verify the sort in the following code.

    <pre>Option Explicit
    Public Sub WBSortArray()
    Dim a() As String
    Dim blnBooBoo As Boolean
    Dim i As Long


    SetArray a()
    blnBooBoo = False
    WordBasic.SortArray a(), False
    Do
    For i = 1 To UBound(a)
    If a(i - 1) > a(i) Then
    Debug.Print "Straight compare failed"
    blnBooBoo = True
    Exit Do
    End If
    Next i
    Exit Do
    Loop
    Do
    For i = 1 To UBound(a)
    If StrComp(a(i - 1), a(i), vbTextCompare) = 1 Then
    Debug.Print "vbTextCompare failed"
    blnBooBoo = True
    Exit Do
    End If
    Next i
    Exit Do
    Loop
    Do
    For i = 1 To UBound(a)
    If StrComp(a(i - 1), a(i), vbBinaryCompare) = 1 Then
    Debug.Print "vbBinaryCompare failed"
    blnBooBoo = True
    Exit Do
    End If
    Next i
    Exit Do
    Loop

    If blnBooBoo Then
    For i = 0 To UBound(a)
    Debug.Print a(i)
    Next i
    End If
    End Sub
    Private Sub SetArray(a() As String)
    ReDim a(9)
    a(0) = "Accessing"
    a(1) = "Recordset"
    a(2) = "provide"
    a(3) = "hard"
    a(4) = "NotOverridable"
    a(5) = "Layout"
    a(6) = "your"
    a(7) = "servername"
    a(8) = "ProjectInstaller"
    a(9) = "Premium"
    End Sub
    </pre>


  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    I bet this is covered in the Hacker's Guide to Word for Windows, but where I am currently I do not have access to my copy of it.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    I tried looking in the 2nd edition, but the index is so poorly done, I doubt that I'd find anything.
    Perhaps I'll tak a look at 1st edition.

    If you take a look at the updated (yesterday) http://www.standards.com/Sorting/SortPerfo...escription.html, you'll find an example of the strange sort produced by WordBasic.SortArray.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    I've looked at both editions of the hacker's guide, and a few other sources.
    The info just is not there.

    Sometime last October, I powered down the 486 on which I have Word 6 and Word 7.
    Reluctantly, today, I turned the critter on, hoping that it be happy to see me, and yield the desired info.
    Alas, 'twas not to be.

    I created a SortArray example and got the same result in Word 97 as in the VBA versions of Word.
    Looking at the Help yielded nothing useful.

    486 was then powered down.
    Wonder how many monts before I turn it on again>

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    This issue of some degree of "case sensitivity" in SortArray sounds like an old issue, but I'm away from the bookshelf so I can't check any sources. Funny, though, I thought capitals sorted before lower case (ASCII order), not the other way around. Definitely strange.

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    It's worse than that.
    VB is a general programming language that gives a choice, betwen a binary compare (case sensitive) and Text compare (case insensitive).

    Using those two models one is free to whatever one wants in a particular app.

    However, the methods used by WordBasic.SortArray, Excel and Word's Sort method and the VB 6 ListBox Sort property do not strictly follow the binary/text models.
    And, as I've pointed out WordBasic.SortArray is the strangest of the lot.

    In order to program, one must know how the sorting algorithm works, e.g., to enable one to do a binary search, one must know how the sort works.

    In the past (obviously, I could not have done anything in the future), I've used WB.SA a lot, but the data has always been either numeric or strings of a well-behaved form, so I never noticed the issue.

    I, and at least one other person, have noticed the deviation from the expected binary/text comparison models and, of course, to be polite, MSFT does document anything adequately.

    I wonder what they did in .NET with sorts, I know there's a Sort class, but it will be a while before I try to analyze that.

  7. #7
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    Pity your download doesn't contain the source code. I know some other ways to sort data, that I'd like to compare with the ones in your exe.

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    The souce code for most of the sort roitines is included.

    If you read the associated HTML document(S), you will find a link to sort codes.

    I am not separately specifying that link because I believe that it is necessary for folkes to read the associated documentation before running thr problem, so the link is the reward/punishment for reading the associated ocumentation. And I may choose to change that link at any time.

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    I found the routines, but as long as I can't incorporate my own routines in your Sortperformance.exe file I can't make an objective performance analysis of my own algorhythms.

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    It's not hard to write a front end.

    Need not be as complex as the one I'm using.

    For example, if you purchase RodStephens book, he has a bunch of sorting tests with his own front end that you could modify.

  11. #11
    Star Lounger
    Join Date
    Jan 2001
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    Although I can

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: WordBasic.SortArray (All VBA versions of Word)

    Version 1.2.0 of the program was modified to allow character data and ther program was modified to handle both case sensitive and case insensitive but I have not posted the modified code, nor am I planning on doing so.

    The sort code does whatever is done by Option Compare Text or Option Compare Binary.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •