Announcement

Collapse
No announcement yet.

ARRAY SORT 'misbehaving'

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ARRAY SORT 'misbehaving'

    Array is Dim'd and used throughout earlier code. Then printing it to screen shows that the array does contain data like:
    A$(0) = "1234-Fred"
    A$(1) = "9764-Joe"
    A$(2) = "3622-Mary"
    A$(3) = "1922-Peter"
    A$(4) = "7325-Nancy"
    ARRAY SORT A$(), COLLATE UCASE, DESCEND' sorts A$() in descending order; case-insensitive according to documentation and produces this:

    A$(0) = "9764-Joe"
    A$(1) = "7325-Nancy"
    A$(2) = "3622-Mary"
    A$(3) = "1922-Peter"
    A$(4) = "1234-Fred"
    All OK to here.......

    But, doing
    ARRAY SORT A$(), COLLATE UCASE, ASCEND or
    ASSAY SORT A$(), COLLATE UCASE produces
    A$(0)=""
    A$(1)=""
    A$(2)=""
    A$(3)=""
    A$(4)=""

    Am I missing something here or is there really something wrong with the ASCEND function?






  • #2
    Actual code would be critical to troubleshoot.

    Do a MSGBOX A$(1) before and then after the SORT and what's the result?
    That will tell you if it is the SORT doing it or it was cleared before you entered the SORT.
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

    Comment


    • #3
      Thanks George.

      Yep doing a MSGBOX A$(1) immediately before the ARRAY SORT A$(), COLLATE UCASE shows that A$ did contain "9764-Joe".
      Doing a MSGBOX A$() immediately after that sort shows that A$="".

      So whatever is screwing is in the ARRAY SORT, COLLATE UCASE command.

      Comment


      • #4
        Just out of curiosity do the same test but use this code, most specifically AFTER the array sort.

        Code:
        MSGBOX A$(1) + $CRLF + FORMAT$(LEN(A$(1))) + $CRLF + FORMAT$(ASC(A$(1))) + $CRLF + FORMAT$(UBOUND(A$)) + $CRLF + A$(UBOUND(A$))
        Is the array.declared as something like DIM A$(4) AS STRING (i.e. elements 0-4), or is it some other number like DIM A$(10) AS STRING (i.e. elements 0-10, etc.).

        What I am trying to see is if you array bounds are larger then your actual data set and you have items in the array which wind up sorting LOWER in the sequence due to them having lower ASCII values.
        <b>George W. Bleck</b>
        <img src='http://www.blecktech.com/myemail.gif'>

        Comment


        • #5
          Owen

          Greetings - I can see your place from my beach - well not quite!

          It is extremely unlikely that this is a bug. So start from that premise

          I have had too many NZ reds to write the code and check

          I do not know what the problem is. But maybe, your array has some blank fields in it. That would give you this result. So put in an LBOUND and UBOUND or two! And check that out.

          But anyway - the likelihood of this being a bug is close to zilch. This was a hard lesson that I learnt in my programming childhood - about 50 years ago.

          Kerry
          [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
          Kerry Farmer

          Comment


          • #6
            A bounds problem is my is my guess too...

            Confirm by using this instead, to make sure you're only sorting the number of elements you want sorted ...
            Code:
            Array Sort A$() for 5

            Comment


            • #7
              To make sure in this case, check entire array for empty items before sorting, for example like:
              Code:
                LOCAL i AS LONG, sBuf AS STRING
                FOR i = LBOUND(A$) TO UBOUND(A$)
                  IF LEN(A$(i)) = 0 THEN sBuf = sBuf + STR$(i)
                NEXT
                MSGBOX sBuf ' which items, if any, were empty..

              Comment


              • #8
                PS, if ARRAY DELETE has been used somewhere, it only throws away the data and sort of moves the empty item to last pos in array. REDIM PRESERVE minus last item is needed to remove deleted item completely from array. Something like:
                Code:
                  ARRAY DELETE A$(i)
                  REDIM PRESERVE A$(UBOUND(A$) - 1)

                Comment


                • #9
                  I concur - almost certainly blank records in the array.

                  Code:
                  ARRAY SORT A$(), COLLATE UCASE, DESCEND
                  ARRAY SCAN A$() < " " to lngFirstBlank
                  IF lngFirstBlank > 0 THEN  ' if zero, then no blank records found)
                  ? STR$(UBOUND(A$()) - lngFirstBlank + 1) & " blank records in array"
                  END IF
                  Alternatively, a quick and easy test. After the ASC sort, does A$(UBOUND(A$())) contain "9764-Joe""
                  --
                  [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                  PNG Domain Hosting[/URL]

                  Comment


                  • #10
                    Fixing the problem AFTER sorting the data looks like closing the gate AFTER everything has escaped. The problem should be fixed BEFORE the sort at the level of filtering the input data so there are no blanks being added to the array. If the array member count is larger than the number of items, you truncate the array after all of the non blank data has been added to it.
                    hutch at movsd dot com
                    The MASM Forum

                    www.masm32.com

                    Comment


                    • #11
                      Originally posted by Steve Hutchesson View Post
                      Fixing the problem AFTER sorting the data looks like closing the gate AFTER everything has escaped. The problem should be fixed BEFORE the sort at the level of filtering the input data so there are no blanks being added to the array. If the array member count is larger than the number of items, you truncate the array after all of the non blank data has been added to it.
                      I don't see where anyone is suggesting fixing the problem after sorting the data,

                      All of the suggestions have been for debugging code to identify the actual problem. Since we don't have any information about how the "Array is Dim'd and used throughout earlier code", it's rather pointless to talk about how to fix the as yet undiagnosed problem.

                      We have no idea whether blanks are "being added to the array" nor whether there are more array members than items. There are many ways that array items can end up blank, including deleting items or incorrectly editing items.
                      --
                      [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                      PNG Domain Hosting[/URL]

                      Comment


                      • #12
                        Apply the KISS principal and do the basic things to get the process reliable.

                        1. Filter out any blanks.
                        2. Truncate the array if it has more members that items added to it.

                        What is the result ?
                        (a) No blanks added.
                        (b) No unused array location as blanks.

                        How does that song go again ? "Whose the leader of the club . . . ."
                        hutch at movsd dot com
                        The MASM Forum

                        www.masm32.com

                        Comment


                        • #13
                          Owen, some source code please, that is minimal, but compilable, and demos the problem.

                          You should have done in the first place, but now disagreements over the guesses have started. (A couple good guesses IMO, but you're not answering questions intended to "pin down" the problem either.)((simply haven't had a chance to check in?))

                          Cheers,
                          Dale

                          Comment


                          • #14
                            Steve, are you trying to lead us somewhere by referencing that song?
                            This is likely a problem of dimension, not dementia.
                            Insufficient code given for one hundred percent certainty, but on the basis of code shown, the most probable reason has been surmised.
                            Rod
                            "To every unsung hero in the universe
                            To those who roam the skies and those who roam the earth
                            To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                            Comment


                            • #15
                              So many thanks - the most obvious misunderstandings are often the ones that waste the time.

                              The array was earlier DIM A$(1000) and was thus full of nulls which obviously are <ascii 0-255.

                              Kerry - we seem to share the weather these days..... beautiful winters day here.

                              Comment


                              • #16
                                Originally posted by Steve Hutchesson View Post
                                Apply the KISS principal and do the basic things to get the process reliable.

                                1. Filter out any blanks.
                                2. Truncate the array if it has more members that items added to it.

                                What is the result ?
                                (a) No blanks added.
                                (b) No unused array location as blanks.

                                How does that song go again ? "Whose the leader of the club . . . ."
                                Yep, thank you for yet another MM approach to a problem with an unknown cause.

                                Step 1. Identify the cause(s) of the blank records.
                                Step 2. Determine an appropriate solution.
















                                --
                                [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                                PNG Domain Hosting[/URL]

                                Comment


                                • #17
                                  Originally posted by Rodney Hicks View Post
                                  Steve, are you trying to lead us somewhere by referencing that song?
                                  This is likely a problem of dimension, not dementia.
                                  Insufficient code given for one hundred percent certainty, but on the basis of code shown, the most probable reason has been surmised.
                                  He uses it regularly to denigrate some forum members who have been using PB professionally to develop complex solutions for many years.

                                  Perhaps a mirror is called for.
                                  --
                                  [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                                  PNG Domain Hosting[/URL]

                                  Comment


                                  • #18
                                    Now now mouseketeers, you are assuming that I was responding to you with my original post. Owen asked a question and posted some code so I posted a response to his question, not the list of following platitudes. Now for Stuart, go back to your post #11 and see who thought they could dictate how the question was answered, how hard do you have to guess that it was you who thought you could take over the conversation like you normally do.

                                    Now since you appear to have problems doing simple diagnostics, we will break it down again.

                                    1. Filter out any blanks.

                                    Now if you bothered to read Owen's original post, you would see that he detailed the problem in the following code snippet.
                                    Code:
                                    A$(0)=""
                                    A$(1)=""
                                    A$(2)=""
                                    A$(3)=""
                                    A$(4)=""
                                    In case you have missed it, these are blanks so step one (1) in the diagnosis is to remove the blanks at the input stage.

                                    2. Truncate the array if it has more members that items added to it.

                                    Allocating a large array without knowing the final total is not an uncommon problem, especially if there is the potential of some of the entries not being added due to condition (1) above so after you have added all of the entries to the array, if the entry count is less than the array count, you remove the unused section of the array by truncating it. This is removing any blanks at the output stage.

                                    Now once you have a 1 to 1 correlation between array entries and array member count, you simply sort it and it works correctly. This is why you apply the KISS principle.

                                    Rod,
                                    Steve, are you trying to lead us somewhere by referencing that song?
                                    NO, I am trying to avoid hearing it but its strained refrain keep fouling legitimate posts.

                                    I will let you in on a little secret as Bob authorised it, I was a member of the beta team for the first version of the DDT system that Bob developed and I know exactly why it was designed so that a wide range of folks who just did not have the life and time to learn the Windows API could produce user interfaces for their work. It is a system that worked well then and it still works well now. Where the Mickey Mouse Club botched it was the idea that "We write code this way, you should too or we will keep fouling valid posts with claptrap."

                                    What the mouseketeers forget is that many people write in many different styles, you can still write line numbered basic if you want, then there are still members who write GOTO basic, then there is the early form of Microsoft basic that PB can do and when you are through playing games you can emulate C using the C runtime DLL (MSVCRT) or even worse, start using the direct Windows API functions if you can tolerate the mouseketeers whining away about non-club compliance. Now if you really want to offend the mouseketeers start writing algorithms in assembler using PowerBASIC and the chorus of stupidity will reach a chrescendo of political correctness, imbecile pecking orders and the like.

                                    I can only congratulate the mouseketeers on successfully selling the idea that "We took the Power out of BASIC".
                                    hutch at movsd dot com
                                    The MASM Forum

                                    www.masm32.com

                                    Comment


                                    • #19
                                      Originally posted by Steve Hutchesson View Post
                                      ... we will keep fouling valid posts with claptrap."
                                      Pot, meet kettle!

                                      --
                                      [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
                                      PNG Domain Hosting[/URL]

                                      Comment


                                      • #20
                                        NO, I am trying to avoid hearing it but its strained refrain keep fouling legitimate posts.
                                        ..thou dost protest too much, methinks.... oh, somebody already said that!
                                        While many people write in many different styles, they also write for many different purposes. Since my performance, which only has to satisfy me, needs very little more than what I get from DDT, is that a reason to make disparaging remarks about DDT? Is it not possible that you have a more complicated need for your programming goals than others have for their goals?

                                        Since I'm off topic I'll police meself and not respond further.
                                        Rod
                                        "To every unsung hero in the universe
                                        To those who roam the skies and those who roam the earth
                                        To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

                                        Comment

                                        Working...
                                        X