Announcement

Collapse
No announcement yet.

Listbox Sort not same as Array Sort

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listbox Sort not same as Array Sort

    '
    Code:
    'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
    #Compile Exe                                                         
     
    #Include "WIN32API.INC"
     
    Function PBMain
      Global hdlg As Dword
      Dialog New Pixels, hdlg, "ListBox sorts", , , 400, 400, %WS_SYSMENU To hdlg
      
        Local Wdth&, Hght&, Stile&, ctr&, ctr1&, t$, StartAt&
        Local Id1&, id2&, id3&, a$(), b$(), c$()
        Local StileA&, StileB&, StileC&
        
        'build arrays
        ctr = 25
        Dim a$(ctr), b$(ctr), c$(ctr)
        For ctr = LBound(a$()) To UBound(a$())
           'random string
            t$ = String$(10, Chr$(Rnd(65, 90)))
              ctr1 = Rnd(1, 2)
                If ctr1 = 1 Then t$ = "_" & t$
            a$(ctr) = t$
            b$(ctr) = t$
            c$(ctr) = t$
        Next ctr
                           
         Array Sort c$()                  
          Wdth = 100
          Hght = 300
           
      StartAt = 10
      StileA = %LBS_NOINTEGRALHEIGHT Or %WS_VSCROLL Or %LBS_NOTIFY 'no sort
      Control Add Label, hdlg, -1, "Original Unsorted", StartAt + 5, 1, Wdth, 14
      Control Add ListBox, hdlg, id1, a$(), StartAt, 16, Wdth, Hght,  StileA
     
      StartAt = StartAt + Wdth + 40
      StileB =  %LBS_STANDARD 'includes sort style
      Control Add Label, hdlg, -1, "Listbox Sorted", StartAt, 1, Wdth, 14
      Control Add ListBox, hdlg, id2, b$(), StartAt, 16, Wdth, Hght,  StileB
     
      StartAt = StartAt + Wdth + 40
      StileC = StileA 'no sort
      Control Add Label, hdlg, -1, "Array Sorted", StartAt, 1, Wdth, 14
      Control Add ListBox, hdlg, id3, c$(), StartAt, 16, Wdth, Hght,  StileC
     
      
         Dialog Show Modal hDlg  
    End Function
    '
    '
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

  • #2
    I'm not sure what this means, but it certainly is interesting.

    I for sure was surprised to see the two LBs on the right were not identical.

    Please sate my curiosity: how did you happen to discover this behavior?
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Originally posted by Michael Mattias View Post
      I'm not sure what this means, but it certainly is interesting.
      What it means is the Listbox Sort is not identical to Array Sort (Chr$(95) is ignored in the former and acknowledged in the latter).
      I for sure was surprised to see the two LBs on the right were not identical.

      Please sate my curiosity: how did you happen to discover this behavior?
      I'm a curious guy?
      It's a pretty day. I hope you enjoy it.

      Gösta

      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

      Comment


      • #4
        It appears that Windows uses a Sort which has some rules about non-alphabetic characters, which puts them before characters, even if the ascii code is higher than the characters.

        PB is sorting according to the ascii values and in proper order.

        Here is a modified version which adds the ascii value of the first character to each item. It makes it easier to see what is happening.

        Code:
        'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
        #COMPILE EXE
        #INCLUDE "WIN32API.INC"
        FUNCTION PBMAIN
          GLOBAL hdlg AS DWORD
          DIALOG NEW PIXELS, hdlg, "ListBox sorts", , , 400, 400, %WS_SYSMENU TO hdlg
            LOCAL Wdth&, Hght&, Stile&, ctr&, ctr1&, t$, StartAt&
            LOCAL Id1&, id2&, id3&, a$(), b$(), c$()
            LOCAL StileA&, StileB&, StileC&
            'build arrays
            ctr = 25
            DIM a$(ctr), b$(ctr), c$(ctr)
            FOR ctr = LBOUND(a$()) TO UBOUND(a$())
               'random string
                t$ = STRING$(5, CHR$(RND(65, 90)))
                  ctr1 = RND(1, 2)
                    IF ctr1 = 1 THEN t$ = "_" & t$
                a$(ctr) = t$+" "+STR$(ASC(t$))
                b$(ctr) = t$+" "+STR$(ASC(t$))
                c$(ctr) = t$+" "+STR$(ASC(t$))
            NEXT ctr
             ARRAY SORT c$()
              Wdth = 100
              Hght = 300
          StartAt = 10
          StileA = %LBS_NOINTEGRALHEIGHT OR %WS_VSCROLL OR %LBS_NOTIFY 'no sort
          CONTROL ADD LABEL, hdlg, -1, "Original Unsorted", StartAt + 5, 1, Wdth, 14
          CONTROL ADD LISTBOX, hdlg, id1, a$(), StartAt, 16, Wdth, Hght,  StileA
          StartAt = StartAt + Wdth + 40
          StileB =  %LBS_STANDARD 'includes sort style
          CONTROL ADD LABEL, hdlg, -1, "Listbox Sorted", StartAt, 1, Wdth, 14
          CONTROL ADD LISTBOX, hdlg, id2, b$(), StartAt, 16, Wdth, Hght,  StileB
          StartAt = StartAt + Wdth + 40
          StileC = StileA 'no sort
          CONTROL ADD LABEL, hdlg, -1, "Array Sorted", StartAt, 1, Wdth, 14
          CONTROL ADD LISTBOX, hdlg, id3, c$(), StartAt, 16, Wdth, Hght,  StileC
        
             DIALOG SHOW MODAL hDlg
        END FUNCTION
        '
        '
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          It may even do the new XP sorting too that tries to put things in numeric order, etc.

          Like before:
          1
          10
          2
          20
          3
          4
          5
          6
          7
          8
          9

          Now goes:
          1
          2
          3
          4
          5
          6
          7
          8
          9
          10
          20

          And, of course this can be modified by a registry key to make it even more fun to keep track of.
          sigpic
          Mobile Solutions
          Sys Analyst and Development

          Comment


          • #6
            Originally posted by Roger Garstang View Post
            And, of course this can be modified by a registry key to make it even more fun to keep track of.
            Ah, yes. I can see it now. To the wife:

            "Just put the cd in the little slide out tray on your computer, dear, and the program will install automatically."

            "Oh, and then go to the Cmd line and type RegEdit ..."

            =========================
            It is hard to free fools
            from chains they revere.
            ~ Voltaire
            =========================
            It's a pretty day. I hope you enjoy it.

            Gösta

            JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
            LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

            Comment


            • #7
              put the cd in the little slide out tray on your computer, dear, and the program will install automatically..Oh, and then go to the Cmd line and type RegEdit ..
              This is why setup tools are so handy. Using Inno Setup making a registry entry or at 'install time' is a piece of cake.. and you can also make it a user option. .

              If you want to provide a CD which is "plug in and it installs" why not have it install completely?
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                This is why setup tools are so handy. Using Inno Setup making a registry entry or at 'install time' is a piece of cake.. and you can also make it a user option. .

                If you want to provide a CD which is "plug in and it installs" why not have it install completely?
                Are you being sardonic? Or was I?
                It's a pretty day. I hope you enjoy it.

                Gösta

                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                Comment


                • #9
                  Not at all.

                  I really, truly believe that an application designed for "Suzy User" to install herself can't require "regedit" and setup tools make it easy for the developer to make this happen.

                  I also really, truly believe that any application designed for "Suzy User" to install herself and does request she use "regedit" is the mark of a rank amateur developer and reflects poorly on the entire professional software developer community.




                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Originally posted by Michael Mattias View Post
                    ... is the mark of a rank amateur developer and reflects poorly on the entire professional software developer community.

                    MCM
                    Wow! A whole new level of sardonicism. Talk about going from DDT to SDK.

                    ================================
                    An open foe may prove a curse;
                    but a pretended friend is worse.
                    Ben Franklin
                    ================================
                    It's a pretty day. I hope you enjoy it.

                    Gösta

                    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                    Comment


                    • #11
                      Originally posted by Michael Mattias View Post

                      I also really, truly believe that any application designed for "Suzy User" to install herself and does request she use "regedit" is the mark of a rank amateur developer and reflects poorly on the entire professional software developer community.

                      MCM
                      One hundred percent right, Michael. The install program must do everything that needs to be done for the program to get installed properly.

                      Even programming for fools is tricky!.
                      Whenever I finish writting a new program that is supossedly idiot proof, I hand it over to two or three people at the office for testing. It always amazes me how they find programming flaws right at the first click!.

                      Comment


                      • #12
                        Whenever I finish writting a new program that is supossedly idiot proof, I hand it over to two or three people at the office for testing. It always amazes me how they find programming flaws right at the first click!.
                        I don't see programming errors much, but feature content is something else.

                        After weeks (which seem like months) of working out details with my client contact, it basically never fails that in the first five minutes Susie User will say something like, "this is nice but it would have been better if you had included <X>."

                        At which point everyone - myself included -gives himself a big :doh: and tells himself, "of course we should have included <X>!"

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment

                        Working...
                        X