texaspete
New Member
Actually I am an old member. just been working hard for a long time
Posts: 21
|
Sorting
Dec 27, 2019 8:53:08 GMT -5
Post by texaspete on Dec 27, 2019 8:53:08 GMT -5
Had some help earlier on sorting. CODE -- from Alincon2001 article "Sort on 2 Fields", just what I needed
' to be able to "sort" my grocery list items by "category" and/then
' "item name". Any other "sort" would NOT work for me.
' cwr mod 02-19-2017
I was trying Alincion methodology. I was combining fields 5 & 7 to sort on. Actually field size NAMELIST$ (8 DEEP , 32 FIELDS WIDE) '===== DIM NAMELIST$(5000, 31) I am sorting towns and zip. LISTSIZE =8
field 5=5:field7=7' fields to sort on
FOR Z= 1 TO LISTSIZE
NAMELIST$(Z,0) = NAMELIST$(Z,5) + NAMELIST$(Z,7)
NEXT
'===========================
sort NAMELIST$(),1,LISTSIZE ,0
I am receiving an unusual error.
Can anyone see what it might be?
Thanks Texas Pete
|
|
|
Sorting
Dec 27, 2019 9:40:58 GMT -5
Post by tsh73 on Dec 27, 2019 9:40:58 GMT -5
Merry Christmas! As they used to say "telepaths are all on vacation" could you at least post that error?
|
|
|
Sorting
Dec 27, 2019 9:53:09 GMT -5
Post by Rod on Dec 27, 2019 9:53:09 GMT -5
Yes the method works for me.
DIM NAMELIST$(5000, 31) NAMELIST$(3,5)="A" NAMELIST$(3,7)="B" NAMELIST$(2,5)="A" NAMELIST$(2,7)="C" NAMELIST$(1,5)="B" NAMELIST$(1,7)="A" LISTSIZE=3
FOR Z= 1 TO LISTSIZE NAMELIST$(Z,0) = NAMELIST$(Z,5) + NAMELIST$(Z,7) NEXT
'===========================
sort NAMELIST$(),1,LISTSIZE ,0
FOR Z= 1 TO LISTSIZE print NAMELIST$(Z,5),NAMELIST$(Z,7) NEXT
|
|
|
Sorting
Dec 27, 2019 11:00:56 GMT -5
Post by BeeTrap on Dec 27, 2019 11:00:56 GMT -5
Ooooo, spooky!! Be careful following anything I have posted, you may get even more lost! Happy Holidays, all. cwr
|
|
ntech
New Member
Posts: 49
|
Sorting
Dec 27, 2019 12:41:58 GMT -5
Post by ntech on Dec 27, 2019 12:41:58 GMT -5
Merry Christmas!
texaspete, what are you trying to do by this: "field 5=5:field7=7' fields to sort on"?
|
|
|
Sorting
Dec 28, 2019 5:59:01 GMT -5
Post by meerkat on Dec 28, 2019 5:59:01 GMT -5
Why not simply create a grocery database. Something like;
CREATE TABLE grocery ( grocNum INT(4), type VARCHAR(3), descr VARCHAR(30), short VARCHAR(10), vendNum SMALLINT(2), price DECIMAL(8,2), uom VARCHAR(5), notes TEXT, photoId varchar(22) ) ; CREATE UNIQUE INDEX grocNum ON grocery (grocNum);
Then you can sort and list it any way you like with the SELECT statement.
To sort by description within type; SELECT * FROM grocery ORDER BY cat,type
To find all grocery items that have a Unit Of Measure of 'box' and contains the word 'good' in the nodes somewhere, and Sorted by short description within price descending SELECT * FROM grocery WHERE uom = 'box' AND notes like '%good%' ORDER BY price desc, short
|
|
texaspete
New Member
Actually I am an old member. just been working hard for a long time
Posts: 21
|
Sorting
Dec 28, 2019 9:12:28 GMT -5
Post by texaspete on Dec 28, 2019 9:12:28 GMT -5
ntech, field 5 is for cities field 7 is for zip codes
Meerkat, Thank you for your suggestion. I am converting a program written about 20 years back from another language. The new version has even more fields . With more information in it. A quick proper sort will make all the other code work that works with it. I will keep your suggestion in mind . I had written a bubble sort routine many years ago. It failed, because of the difference that LB seeming handles integers differently than the other basic. Thanking all of you for your suggestions and input. I occasionally get brain fog, finding all the differences between the two codes. It definitely, brings new light that all basic languages are not the same. May the fog lift o' Lord!
Thanking all the help! Texas Pete
|
|
texaspete
New Member
Actually I am an old member. just been working hard for a long time
Posts: 21
|
Sorting
Dec 28, 2019 10:18:20 GMT -5
Post by texaspete on Dec 28, 2019 10:18:20 GMT -5
Rod, I worked out and example based on your example. I read my file into the cpu and printed. Even though I had Put the two strings together. It only sorted properly on the first field. I put the zip in the first field and then it sort zip first and then city . This worked when sorting on the field zero. It did not get the zip in the correct order with the city , unless numbers were first.
If I sorted city first and then zip. Some of the zip numbers would be out of order. Any How the brain fog has Lifted!! I am sure it has something to do with precedence.
Texas Pete
|
|
|
Sorting
Dec 28, 2019 12:01:21 GMT -5
Post by Rod on Dec 28, 2019 12:01:21 GMT -5
Show us a few records till we see what you are sorting on.
|
|
|
Sorting
Dec 28, 2019 17:23:49 GMT -5
Post by tsh73 on Dec 28, 2019 17:23:49 GMT -5
I suspect then doing
NAMELIST$(Z,0) = NAMELIST$(Z,5) + NAMELIST$(Z,7) one have to pad cities with spaces to be of equal length.
EDIT with something like this
print "-0123456789-" n=10 print ">";padl$("123", n);"<" print ">";padl$("absdefghij", n);"<" print ">";padl$("ABCDEFGHIJKLMN", n);"<" end
function padl$(a$, n) padl$=left$(a$+space$(n), n) end function
|
|