Sorting Alphabetically - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Sorting Alphabetically (/thread-10077.html) |
Sorting Alphabetically - jelamb - 01-03-2008 Old timer trying to recreat a sort routine I did back in the 80s to sort a list of items alphabetically according to the variable ID$. See code below that does not seem to work. Success seems to hinge on comparing value of the string variable. Any Suggestions?? 700 REM ALPHABETIZE DATA BY DESCRIPTION = ID$ Â Â Â Â FOR N = 1 TO NOR Â Â Â Â FOR M = 1 TO NOR - 1 Â Â Â Â IF ID$(M)> ID$(M + 1) THEN GOTO 720 ELSE GOTO 799 720Â Â SCTEMP$ = SC$(M) Â Â Â Â IDTEMP$ = ID$(M) Â Â Â Â UCSTTEMP = UCST(M) Â Â Â Â TQTYTEMP = TQTY(M) Â Â REM SWAP LINE ITEMS IN LIST Â Â Â Â SC$(M) = SC$(M + 1) Â Â Â Â ID$(M) = ID$(M + 1) Â Â Â Â UCST(M) = UCST(M + 1) Â Â Â Â TQTY(M) = TQTY(M + 1) Â Â Â Â SC$(M + 1) = SCTEMP$ Â Â Â Â ID$(M + 1) = IDTEMP$ Â Â Â Â UCST(M + 1) = UCSTTEMP Â Â Â Â TQTY(M + 1) = TQTYTEMP 799Â Â NEXT M Â Â Â NEXT N Â Â Â Â RETURN 502 Re: Sorting Alphabetically - Mac - 01-03-2008 Well, I added some code to make your program function, but I don't have time right now to find the bug. Maybe later unless someone else finds it. Run this and note that sort does not work. Code: CONST NOR = 5 Re: Sorting Alphabetically - Mac - 01-03-2008 Somehow you lost these commands: Code: Â Â Â REM Part 1 of the swap Here they are inserted Code: CONST NOR = 5 Re: Sorting Alphabetically - Ralph - 01-04-2008 Good going, Mac! Â Only thing is, first two array variables are strings, but, second two are numerals, not strings Re: Sorting Alphabetically - Mac - 01-04-2008 (01-04-2008, 02:47 AM)Ralph link Wrote:Good going, Mac! Â Only thing is, first two array variables are strings, but, second two are numerals, not strings Good catch. I didn't bother to display those two, so didn't notice the bug. I presume his main program has everything initialized properly. Mac Re: Sorting Alphabetically - jelamb - 01-12-2008 Mac, Thanks for your efforts. As it turns out, the code I gave works perfectly now, i.e. I did not change anything in that list. I did make some other small changes in my program and, as you suggest, it may have been an initialization error. Sorry for the confusion and thanks again for your responses. John |