Liberty BASIC Community Forum
« sort routine tune-up-needed »

Welcome Guest. Please Login or Register.
Oct 18th, 2017, 08:05am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: sort routine tune-up-needed  (Read 169 times)
debluzz
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 133
xx sort routine tune-up-needed
« Thread started on: Oct 9th, 2017, 09:30am »

These are two data files I use.
they are copied to the txt files using excel.
i'v been told the problem is in my data...

the problem i'm having is my sort routine on the date field.
I do sorts on the other fields, all is cool.
what I need is the files sorted on date with the most current on top and the oldest on the bottom
the xxx yyyyyyyyyy is the name field
the ttt rrrrrrrrrrr is also a name field
<CODE>
XXX YYYYYYYYYYYY 6/27/2017 B 73 29.95 5 5 5 3 3 30.02 Got Busy Far, Rail
XXX YYYYYYYYYYYY 6/22/2017 C 73 29.96 6 7 4 2 1 29.96 Tngld 1st, Arrived
XXX YYYYYYYYYYYY 6/16/2017 C 73 30.53 2 8 7 6 3 30.86 All Hustle, Midtrk
XXX YYYYYYYYYYYY 6/10/2017 B 73 30.18 5 7 8 6 5 30.34 Cautious 1st Turn
XXX YYYYYYYYYYYY 6/5/2017 B 72 29.87 6 6 8 6 6 30.77 Jmd Rush, Inside
XXX YYYYYYYYYYYY 6/1/2017 B 72 29.93 4 6 7 5 5 30.49 Tngld Rush, Blkd Far
XXX YYYYYYYYYYYY 7/1/2017 B 73 29.58 1 6 5 5 4 29.99 Misstep Bckstr, Ins
XXX YYYYYYYYYYYY 7/6/2017 B 72 29.78 2 7 4 2 2 29.8 All Drive, Bidding
XXX YYYYYYYYYYYY 7/9/2017 B 72 29.45 2 6 7 7 5 30.57 Coll 1st Turn, Ins
XXX YYYYYYYYYYYY 7/14/2017 B 73 29.96 3 5 6 6 5 30.47 Minor Late Moves
XXX YYYYYYYYYYYY 7/19/2017 B 72 30.07 3 8 6 6 2 30.57 Late Speed For Place
XXX YYYYYYYYYYYY 7/23/2017 B 72 29.98 4 3 4 4 4 30.42 Blkd Far Tn, Inside
XXX YYYYYYYYYYYY 7/29/2017 B 72 29.95 3 3 8 8 7 30.59 Gave Way 1st, Inside
XXX YYYYYYYYYYYY 8/4/2017 B 72 30.1 7 7 3 3 2 30.26 Late Surge For Plc
XXX YYYYYYYYYYYY 8/8/2017 B 72 29.62 1 7 8 8 8 30.45 Gave Way 1st, Faded
XXX YYYYYYYYYYYY 8/21/2017 B 71 30.39 4 7 8 6 5 30.68 Coll Erly, Blkd Far
XXX YYYYYYYYYYYY 8/26/2017 B 72 29.49 7 7 7 8 8 30.7 Bmpd Rush, Faded
XXX YYYYYYYYYYYY 9/1/2017 C 72 29.92 1 1 1 1 1 29.92 Up And Gone Inside
XXX YYYYYYYYYYYY 9/6/2017 B 71 30.09 8 8 6 6 6 30.83 Trbl 1st, Faded Bck
XXX YYYYYYYYYYYY 9/19/2017 B 72 29.85 2 5 8 8 7 30.52 Not A Threat, Ins
XXX YYYYYYYYYYYY 9/23/2017 B 72 29.76 6 6 7 7 7 30.66 Gave Way 1st, Ins
XXX YYYYYYYYYYYY 9/28/2017 C 71 30.35 1 4 5 2 1 30.35 Major Late Moves
XXX YYYYYYYYYYYY 10/2/2017 B 71 30.56 1 3 6 7 4 30.9 Blkd 1st, Late Speed
<\>

<CODE>
TTTTT RRRRRRRRRR 6/30/2017 C 76 30.12 4 5 2 1 1 30.12 Just In Time, Mid
TTTTT RRRRRRRRRR 7/5/2017 B 76 29.92 4 1 1 1 1 29.92 Never Looked Back
TTTTT RRRRRRRRRR 7/10/2017 A 76 29.83 4 8 2 3 4 30.24 Mild Drive, Inside
TTTTT RRRRRRRRRR 7/15/2017 A 77 30.06 1 3 1 1 1 30.06 Late Push For Win
TTTTT RRRRRRRRRR 7/21/2017 A 76 29.88 5 5 4 3 4 30.49 Rough Trip, Midtrk
TTTTT RRRRRRRRRR 7/26/2017 A 76 29.59 7 3 1 1 3 29.95 Brief Lead, Tiring
TTTTT RRRRRRRRRR 7/31/2017 A 76 29.8 6 7 2 2 3 30.13 Caught Late, Inside
TTTTT RRRRRRRRRR 8/5/2017 A 76 29.83 5 1 1 1 1 29.83 Led Every Step, Ins
TTTTT RRRRRRRRRR 8/11/2017 A 77 29.83 8 8 1 1 8 30.32 Led, Out Of Gas
TTTTT RRRRRRRRRR 8/17/2017 A 76 29.7 6 1 1 1 2 29.74 Overtaken Late, Mid
TTTTT RRRRRRRRRR 8/24/2017 A 77 29.65 3 2 4 7 8 30.75 Erly Gain, Faded Lt
TTTTT RRRRRRRRRR 9/4/2017 A 77 29.89 7 4 2 3 5 30.62 Lost Grnd Far Turn
TTTTT RRRRRRRRRR 9/18/2017 A 76 29.98 6 5 3 3 4 30.7 Erly Bid, Outdrove
TTTTT RRRRRRRRRR 10/2/2017 B 76 30.56 2 4 2 3 7 31.11 Coll 1st, Lost Grnd </>
here is the routine I'm using:
<code>
mainwin 100 22

filedialog "Open", "*.txt", file$
if file$ ="" then end

NumRows =0

open file$ for input as #f
notice "DONE w/SORTING"+" "+"SAVE IN CAPS ONLY.... DOGG...."
while not( eof( #f))
line input #f, dummy$
if dummy$ <>"" then NumRows =NumRows +1 ' find how many rows ( 'NumRows') of data
wend

close #f

dim colWidth( 11), colAlign$( 11) ' hold desired column width and alignment L(eft) or R(ight)

colWidth( 0) =22: colAlign$( 0) ="L" ' Name
colWidth( 1) =10: colAlign$( 1) ="R" ' Date
colWidth( 2) = 2: colAlign$( 2) ="R" ' Grade
colWidth( 3) = 2: colAlign$( 3) ="R" ' Weight
colWidth( 4) = 5: colAlign$( 4) ="R" ' Comp
colWidth( 5) = 1: colAlign$( 5) ="L" ' bx
colWidth( 6) = 1: colAlign$( 6) ="R" ' br
colWidth( 7) = 1: colAlign$( 7) ="R" ' tr
colWidth( 8) = 1: colAlign$( 8) ="R" ' str
colWidth( 9) = 1: colAlign$( 9) ="R" ' fn
colWidth( 10) = 5: colAlign$( 10) ="R" ' Art
colWidth( 11) =22: colAlign$( 11) ="L" ' Com

print "Found "; NumRows; " rows of data in file "; file$
'dim r$( NumRows, 11) ' NB indexes start at ZERO, so 0...11 is columns 1 to 12.
dim r$( NumRows , 12) ' This seems to sort it. WHYhuh
cls
open file$ for input as #inFile

for j =1 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
[skip]
next j

close #inFile

print "Data check. "; "Found "; NumRows; " rows of data in file "; file$
for j =0 to 11
call printSized r$( 0, j), colWidth( j), colAlign$( j)
next j
print

open file$ for input as #inFile

for j =0 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
'we now have the date string in r$(j,2)
'extract the year
y$=right$(r$(j,2),4)
'extract the month adding a leading zero if required
m$=right$("00"+word$(r$(j,2),2,"/"),2)
'extract the day adding a leading zero if required
d$=right$("00"+word$(r$(j,2),1,"/"),2)
'now store yyyymmdd back in in r$(j,2)
r$(j,2)=y$+m$+d$
[skip1]
next j

close #inFile


column=1 'field 1 is the date
print "Sort DATE field# "; column; " CURRENT "
'sort r$(), ( NumRows),0, column ' arrayName, startRow, EndRow,
sort r$(), (NumRows-1), 0, 1 ' arrayName, startRow, EndRow, ColumnForSortOrder
time6 =0: time12 =0
for i =0 to 4
for j =0 to 11
call printSized r$( i, j), colWidth( j), colAlign$( j)
if j = 4 then time6 =time6 +val( r$( i, j))
if j =10 then time12 =time12 +val( r$( i, j))
next j
print
next i
print



sub printSized i$, paddedLength, dirn$
if instr( i$, "/") then i$ =formattedDate$( i$)
if dirn$ ="R" or dirn$ ="" then
i$ =right$( space$( paddedLength) +i$, paddedLength) +" "
else
i$ =left$( i$ +space$( paddedLength), paddedLength) +" "
end if
print i$;
end sub

function formattedDate$( i$)

y$ =right$( "0000" +word$( i$, 3, "/"), 4) +"/"
m$ =right$( "00" +word$( i$, 2, "/"), 2)+"/"
d$ =right$( "00" +word$( i$, 1, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$

end function
</>

I hope this can be resolved easily...without having to change too much

what it is not doing ???
not sorting correctly
<code>
Sort DATE field# 1 CURRENT
XXX YYYYYYYYYYYY 2017/06/09 0B 71 30.09 8 8 6 6 6 30.83 Trbl 1st, Faded Bck
XXX YYYYYYYYYYYY 2017/28/09 0C 71 30.35 1 4 5 2 1 30.35 Major Late Moves
XXX YYYYYYYYYYYY 2017/23/09 0B 72 29.76 6 6 7 7 7 30.66 Gave Way 1st, Ins
XXX YYYYYYYYYYYY 2017/19/09 0B 72 29.85 2 5 8 8 7 30.52 Not A Threat, Ins
XXX YYYYYYYYYYYY 2017/01/090C 72 29.92 1 1 1 1 1 29.92 Up And Gone Insid


if you notice...does not pick up date 2017/02/28
day-month-year

hope someone can help Thanks again
User IP Logged

cor
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 6
xx Re: sort routine tune-up-needed
« Reply #1 on: Oct 9th, 2017, 5:00pm »

I saw your problem and for the most part I have it solved. I have debugged it and have left my debugging statements in the code so you must compare statement by statement in what you now have as your original and what I have changed. Also read the commented and remmed statements for they disclose what has changed and how that was tested.

I have also included portion of the output where the sort results are satisfactory for me. Get back to me if you have questions.

COPY FROM HERE
mainwin 100 22

filedialog "Open", "*.txt", file$
if file$ = "" then end

NumRows =0

open file$ for input as #f

while not( eof( #f))
line input #f, dummy$
if dummy$ <> "" then NumRows = NumRows + 1 ' find how many rows ( 'NumRows') of data
wend
close #f

dim colWidth(11), colAlign$(11) ' hold desired column width and alignment L(eft) or R(ight)

colWidth( 0) =22: colAlign$( 0) ="L" ' Name '<<<<<<<<<<<<<< need to split this into 2 fields and adjust index accordingly
colWidth( 1) =10: colAlign$( 1) ="R" ' Date
colWidth( 2) =10: colAlign$( 2) ="R" ' Grade '<<<<<<<<<<<<<<<<<<<<adjusted to show how this works
'colWidth( 2) = 2: colAlign$( 2) ="R" ' Grade '<<<<<<<<<<<<<<<<<<<<original statement
colWidth( 3) = 2: colAlign$( 3) ="R" ' Weight
colWidth( 4) = 5: colAlign$( 4) ="R" ' Comp
colWidth( 5) = 1: colAlign$( 5) ="L" ' bx
colWidth( 6) = 1: colAlign$( 6) ="R" ' br
colWidth( 7) = 1: colAlign$( 7) ="R" ' tr
colWidth( 8) = 1: colAlign$( 8) ="R" ' str
colWidth( 9) = 1: colAlign$( 9) ="R" ' fn
colWidth(10) = 5: colAlign$(10) ="R" ' Art
colWidth(11) =22: colAlign$(11) ="L" ' Com

print "Found "; NumRows; " rows of data in file "; file$
'dim r$( NumRows, 11) ' NB indexes start at ZERO, so 0...11 is columns 1 to 12.
dim r$(NumRows + 1 , 12) ' This seems to sort it. WHYhuh "COLUMN 1 - XX YYY" CONSTITUTE 2 COLUMNS - NOT ONE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'cls
open file$ for input as #inFile

space$ = chr$(32) 'chr$(9) is NOT the space character, chr$(32) IS!!
for j = 0 to NumRows + 1
line input #inFile, row$
' if eof(#inFile) <> 0 then exit for ' all data except last record read <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if row$ = "" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k = 0 to 11
r$(j, k) = word$(row$, k + 1, space$)

PRINT "r$(j, k)="; r$(j, k); tab(24); ", j="; j; ", k="; k
next k
if eof(#inFile) <> 0 then exit for
[skip]
next j

close #inFile

'****************************************************************************************************

print "Data check. "; "Found "; NumRows; " rows of data in file "; file$
' for j = 0 to 11
' call printSized r$(0, j), colWidth(j), colAlign$(j)
' next j
' print

open file$ for input as #inFile
print "NumRows = "; NumRows
for j = 0 to NumRows '-1
line input #inFile, row$
print row$
' if eof(#inFile) <> 0 then exit for ' all data except last record read <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if row$ ="" then [skip1] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$(j, k) =word$(row$, k + 1, space$) 'chr$(9) is NOT the space character, chr$(32) IS!!
next k
' print "r$( j, k) ="; r$( j, k)
'we now have the date string in r$(j,2)
y$=right$(r$(j,2),4) 'extract the year
print y$
m$=right$("00"+word$(r$(j,2),2,"/"),2) 'extract the month adding a leading zero if required
print m$
d$=right$("00"+word$(r$(j,2),1,"/"),2) 'extract the day adding a leading zero if required
print d$
r$(j, 2)=y$+ "/" + d$ + "/" + m$ 'now store yyyy/mm/dd back in r$(j,2) <<<<<<<<<<<<<restore WITH slashes (/)
if eof(#inFile) <> 0 then exit for
[skip1]
next j
close #inFile

column = 3 ' field 1 is the date
print "Sort DATE field# "; column; " CURRENT "


' for qq = 0 to NumRows
' print r$(qq, 0); " <> "; r$(qq, 1); " <> "; r$(qq, 2); " <> "; r$(qq, 3); " <> "; r$(qq, 4)
' next
'print
sort r$(), 0, NumRows, 2 ' arrayName, startRow, EndRow, ColumnForSortOrder
' for qq = 1 to NumRows
' print r$(qq, 0); " <> "; r$(qq, 1); " <> "; r$(qq, 2); " <> "; r$(qq, 3); " <> "; r$(qq, 4)
' next
'print
'********************************************************************************************
trace 2
time6 = 0: time12 = 0
for i = 1 to NumRows
print
for j =0 to 11
'print "r$(i, j)="; r$(i, j); ", i=";i;", j=";j
call printSized r$(i, j), colWidth(j), colAlign$(j)
if j = 4 then time6 = time6 + val( r$(i, j))
if j = 10 then time12 = time12 + val( r$(i, j))
next j
next i

notice "DONE w/SORTING"+" "+"SAVE IN CAPS ONLY.... DOGG...."
end


sub printSized i$, paddedLength, dirn$
' print "i$="; i$; tab(24); paddedLength; "<>"; dirn$
' if instr(i$, "/") then i$ =formattedDate$( i$)
if dirn$ ="R" or dirn$ ="" then
i$ =right$(space$(paddedLength) + i$, paddedLength) + " "
else
i$ =left$(i$ + space$(paddedLength), paddedLength) + " "
end if
print i$; '; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<reinstate perhaps
end sub

function formattedDate$( i$)
y$ =right$( "0000" +word$( i$, 3, "/"), 4) +"/"
m$ =right$( "00" +word$( i$, 1, "/"), 2)+"/"
d$ =right$( "00" +word$( i$, 2, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$
end function

COPY TO HERE

The below code was used as .txt file based on your used file (your message).

Success

Cor

XXX YYYYYYYYYYYY 9/28/2017 C 71 30.35 1 4 5 2 1 30.35 Major Late Moves
2017
28
09
XXX YYYYYYYYYYYY 10/2/2017 B 71 30.56 1 3 6 7 4 30.9 Blkd 1st, Late Speed
2017
02
10
Sort DATE field# 3 CURRENT

XXX YYYYYYYYYY 2017/06/01 B 72 2 4 6 7 5 5 30.49
XXX YYYYYYYYYY 2017/06/05 B 72 2 6 6 8 6 6 30.77
XXX YYYYYYYYYY 2017/06/10 B 73 3 5 7 8 6 5 30.34
XXX YYYYYYYYYY 2017/06/16 C 73 3 2 8 7 6 3 30.86
XXX YYYYYYYYYY 2017/06/22 C 73 2 6 7 4 2 1 29.96
XXX YYYYYYYYYY 2017/06/27 B 73 2 5 5 5 3 3 30.02
XXX YYYYYYYYYY 2017/07/01 B 73 2 1 6 5 5 4 29.99
XXX YYYYYYYYYY 2017/07/06 B 72 2 2 7 4 2 2 29.8
XXX YYYYYYYYYY 2017/07/09 B 72 2 2 6 7 7 5 30.57
XXX YYYYYYYYYY 2017/07/14 B 73 2 3 5 6 6 5 30.47
XXX YYYYYYYYYY 2017/07/19 B 72 3 3 8 6 6 2 30.57
XXX YYYYYYYYYY 2017/07/23 B 72 2 4 3 4 4 4 30.42
XXX YYYYYYYYYY 2017/07/29 B 72 2 3 3 8 8 7 30.59
XXX YYYYYYYYYY 2017/08/04 B 72 3 7 7 3 3 2 30.26
XXX YYYYYYYYYY 2017/08/08 B 72 2 1 7 8 8 8 30.45
XXX YYYYYYYYYY 2017/08/21 B 71 3 4 7 8 6 5 30.68
XXX YYYYYYYYYY 2017/08/26 B 72 2 7 7 7 8 8 30.7
XXX YYYYYYYYYY 2017/09/01 C 72 2 1 1 1 1 1 29.92
XXX YYYYYYYYYY 2017/09/06 B 71 3 8 8 6 6 6 30.83
XXX YYYYYYYYYY 2017/09/19 B 72 2 2 5 8 8 7 30.52
XXX YYYYYYYYYY 2017/09/23 B 72 2 6 6 7 7 7 30.66
XXX YYYYYYYYYY 2017/09/28 C 71 3 1 4 5 2 1 30.35
XXX YYYYYYYYYY 2017/10/02 B 71 3 1 3 6 7 4 30.9


User IP Logged

cor massar, Dutch member located in Germany
debluzz
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 133
xx Re: sort routine tune-up-needed
« Reply #2 on: Oct 9th, 2017, 8:53pm »

thanks for looking at it, I need to mess with some more.
I'm not getting it to work correctly with the changes.

thanks again
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5543
xx Re: sort routine tune-up-needed
« Reply #3 on: Oct 10th, 2017, 03:00am »

The sorting problem is relatively easy to fix. Your data incoming is in the format mm/dd/yyy. In your function to format the date you mix up mm and dd

Code:
function formattedDate$( i$)

y$ =right$( "0000" +word$( i$, 3, "/"), 4) +"/"
m$ =right$( "00" +word$( i$, 2, "/"), 2)+"/"
d$ =right$( "00" +word$( i$, 1, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$

end function
 


it should be

Code:
function formattedDate$( i$)

y$ =right$( "0000" +word$( i$, 3, "/"), 4) +"/"
d$ =right$( "00" +word$( i$, 2, "/"), 2)+"/"
m$ =right$( "00" +word$( i$, 1, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$

end function
 



Since your incoming date is mm/dd/yyyy the first two characters are the month and the second two the day. You were storing the day to m$ and the month to d$.
« Last Edit: Oct 10th, 2017, 03:01am by Rod » User IP Logged

debluzz
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 133
xx Re: sort routine tune-up-needed
« Reply #4 on: Oct 10th, 2017, 05:05am »

thanks rod,

this is copy of the routine: w/your change:


<code>

mainwin 100 22

filedialog "Open", "*.txt", file$
if file$ ="" then end

NumRows =0

open file$ for input as #f
notice "DONE w/SORTING"+" "+"SAVE IN CAPS ONLY.... DOGG...."
while not( eof( #f))
line input #f, dummy$
if dummy$ <>"" then NumRows =NumRows +1 ' find how many rows ( 'NumRows') of data
wend

close #f

dim colWidth( 11), colAlign$( 11) ' hold desired column width and alignment L(eft) or R(ight)

colWidth( 0) =22: colAlign$( 0) ="L" ' Name
colWidth( 1) =10: colAlign$( 1) ="R" ' Date
colWidth( 2) = 2: colAlign$( 2) ="R" ' Grade
colWidth( 3) = 2: colAlign$( 3) ="R" ' Weight
colWidth( 4) = 5: colAlign$( 4) ="R" ' Comp
colWidth( 5) = 1: colAlign$( 5) ="L" ' bx
colWidth( 6) = 1: colAlign$( 6) ="R" ' br
colWidth( 7) = 1: colAlign$( 7) ="R" ' tr
colWidth( 8) = 1: colAlign$( 8) ="R" ' str
colWidth( 9) = 1: colAlign$( 9) ="R" ' fn
colWidth( 10) = 5: colAlign$( 10) ="R" ' Art
colWidth( 11) =22: colAlign$( 11) ="L" ' Com

print "Found "; NumRows; " rows of data in file "; file$
'dim r$( NumRows, 11) ' NB indexes start at ZERO, so 0...11 is columns 1 to 12.
dim r$( NumRows , 12) ' This seems to sort it. WHYhuh
cls
open file$ for input as #inFile

for j =1 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
[skip]
next j

close #inFile

print "Data check. "; "Found "; NumRows; " rows of data in file "; file$
for j =0 to 11
call printSized r$( 0, j), colWidth( j), colAlign$( j)
next j
print

open file$ for input as #inFile

for j =0 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
y$ =right$( "0000" +word$( i$, 3, "/"), 4) +"/"
d$ =right$( "00" +word$( i$, 2, "/"), 2)+"/"
m$ =right$( "00" +word$( i$, 1, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$

[skip1]
next j

close #inFile


column=1 'field 1 is the date
print "Sort DATE field# "; column; " CURRENT "
sort r$(), ( NumRows),0, column ' arrayName, startRow, EndRow,
'sort r$(), (NumRows-1), 1, 1 ' arrayName, startRow, EndRow, ColumnForSortOrder
time6 =0: time12 =0
for i =0 to 4
for j =0 to 11
call printSized r$( i, j), colWidth( j), colAlign$( j)
if j = 4 then time6 =time6 +val( r$( i, j))
if j =10 then time12 =time12 +val( r$( i, j))
next j
print
next i
print
<\>

it's still doing wrong.

this what it produces:
Data check. Found 23 rows of data in file C:\Users\Lou\Documents\iPICKWIN_LOU\dog1.txt

Sort DATE field# 1 CURRENT
XXX YYYYYYYYYYYYY 2017/09/06 B 71 30.09 8 8 6 6 6 30.83 Trbl 1st, Faded Bck
XXX YYYYYYYYYYYYY 2017/09/28 C 71 30.35 1 4 5 2 1 30.35 Major Late Moves
XXX YYYYYYYYYYYYY 2017/09/23 B 72 29.76 6 6 7 7 7 30.66 Gave Way 1st, Ins
XXX YYYYYYYYYYYYY 2017/09/19 B 72 29.85 2 5 8 8 7 30.52 Not A Threat, Ins
XXX YYYYYYYYYYYYY 2017/09/01 C 72 29.92 1 1 1 1 1 29.92 Up And Gone Inside

.....THE DATE 10/2/2017 DOES'NT EVEN SHOW.
IT SHOULD BE THE TOP LINE FLOWED BY...nothing has changed
« Last Edit: Oct 10th, 2017, 05:15am by debluzz » User IP Logged

tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1684
xx Re: sort routine tune-up-needed
« Reply #5 on: Oct 10th, 2017, 09:10am »

please use button with # symbol above edit field to insert CODE tags around your code so forum formatting does not mess your program.
If should look like this in editor (no spaces around tags)
Code:
[ code ]Paste your Code here[ /code ]
 

and it'll look like this in the post
Code:
Paste your Code here 

User IP Logged

damned Dog in the Manger
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5543
xx Re: sort routine tune-up-needed
« Reply #6 on: Oct 10th, 2017, 09:27am »

The sort command is wrong. The newly formatted date is in field 1 so.

Sort r$(),1,numrows-1,1

That is sort array r$() starting at record 1, stop at the last record and sort it on column 1 the date field.
User IP Logged

debluzz
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 133
xx Re: sort routine tune-up-needed
« Reply #7 on: Oct 10th, 2017, 10:23am »

this is where it's at, to this point:
Not Sorting correctly on the Date Field
what it needs to do is Show most current dates in order in current order

Code:
mainwin 100 22

filedialog "Open", "*.txt", file$
if file$ ="" then end

NumRows =0

open file$ for input as #f
notice "DONE w/SORTING"+"        "+"SAVE IN CAPS ONLY.... DOGG...."
while not( eof( #f))
line input #f, dummy$
if dummy$ <>"" then NumRows =NumRows +1 ' find how many rows ( 'NumRows') of data
wend

close #f

dim colWidth( 11), colAlign$( 11) ' hold desired column width and alignment L(eft) or R(ight)

colWidth( 0) =22: colAlign$( 0) ="L" ' Name
colWidth( 1) =10: colAlign$( 1) ="R" ' Date
colWidth( 2) = 2: colAlign$( 2) ="R" ' Grade
colWidth( 3) = 2: colAlign$( 3) ="R" ' Weight
colWidth( 4) = 5: colAlign$( 4) ="R" ' Comp
colWidth( 5) = 1: colAlign$( 5) ="L" ' bx
colWidth( 6) = 1: colAlign$( 6) ="R" ' br
colWidth( 7) = 1: colAlign$( 7) ="R" ' tr
colWidth( 8) = 1: colAlign$( 8) ="R" ' str
colWidth( 9) = 1: colAlign$( 9) ="R" ' fn
colWidth( 10) = 5: colAlign$( 10) ="R" ' Art
colWidth( 11) =22: colAlign$( 11) ="L" ' Com

print "Found "; NumRows; " rows of data in file "; file$
'dim r$( NumRows, 11) ' NB indexes start at ZERO, so 0...11 is columns 1 to 12.
dim r$( NumRows , 12) ' This seems to sort it. WHYhuh
cls
open file$ for input as #inFile

for j =1 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
[skip]
next j

close #inFile

print "Data check. "; "Found "; NumRows; " rows of data in file "; file$
for j =0 to 11
call printSized r$( 0, j), colWidth( j), colAlign$( j)
next j
print

open file$ for input as #inFile

for j =0 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
'we now have the date string in r$(j,2)
'extract the year
y$ =right$( "0000" +word$( i$, 3, "/"), 4) +"/"
m$ =right$( "00" +word$( i$, 1, "/"), 2)+"/"
d$ =right$( "00" +word$( i$, 2, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$
[skip1]
next j

close #inFile


column=1     'field 1 is the date
 print "Sort DATE field# "; column; "        CURRENT "
'sort r$(), ( NumRows),0, column ' arrayName, startRow, EndRow,
'Sort r$(),NumRows-1,1,1
sort r$(),  (NumRows-1), 1, 1 ' arrayName, startRow, EndRow, ColumnForSortOrder
time6 =0: time12 =0
for i =0 to 4
for j =0 to 11
call printSized r$( i, j), colWidth( j), colAlign$( j)
if j = 4 then time6 =time6 +val( r$( i, j))
if j =10 then time12 =time12 +val( r$( i, j))
next j
print
next i
print
'end if
 column=10
    print: print "Sort FINISH for POST field# "; column; ".          TOP BOX's "

    sort r$(), 0, ( NumRows -1), ( column -1) '   arrayName, startRow, EndRow, ColumnForSortOrder
    time6 =0: time12 =0
    for i =0 to 4
       for j =0 to 11
           call printSized r$( i, j), colWidth( j), colAlign$( j)
           if j = 4 then time6  =time6  +val( r$( i, j))
           if j =10 then time12 =time12 +val( r$( i, j))
       next j
       print
    next i
 print
'end if


 column=11
    print: print "Sort TIME field# "; column; ".                                 TOP TIMES "

    sort r$(), 0, ( NumRows -1), ( column -1) '   arrayName, startRow, EndRow, ColumnForSortOrder
    time6 =0: time12 =0
    for i =0 to 4
       for j =0 to 11
           call printSized r$( i, j), colWidth( j), colAlign$( j)
           if j = 4 then time6  =time6  +val( r$( i, j))
           if j =10 then time12 =time12 +val( r$( i, j))
       next j
       print
    next i
 print
'end if
'next x
' <<<< Routine to count 1's / 2's in column 7 (whole file? or in top fivehuh)>>>>>>>>>>>>>>>>>
num1s =0: num2s =0: num3s =0: num4s =0: num5s =0: num6s =0: num7s =0: num8s =0
for j =0 to NumRows -1 ' in whole file
' for j =0 to 4 ' in chosen top 5

col6 =val( r$( j, 6))
col7 =val( r$( j, 7))
col8 =val( r$( j, 8))
col9 =val( r$( j, 9))
'EARLY
if col6 =1 then num1s =num1s +1 'BREAK 1ST'S
if col6 =2 then num2s =num2s +1 'BREAK 2ND'S
if col7 =1 then num3s =num3s +1 'TURN 1ST'S
if col7 =2 then num4s =num4s +1 'TURN 2ND'S

'LATE
if col8 =1 then num5s =num5s +1 'STRETCH 1ST'S
if col8 =2 then num6s =num6s +1 'STRETCH 2ND'S
if col9 =1 then num7s =num7s +1 'FINISH 1ST'S
if col9 =2 then num8s =num8s +1 'FINISH 2ND'S
next j
'*************************EARLY
BREAK=(((num1s+ num2s)/2)*100)/NumRows'; THIS IS BREAK %
TURN= ((( num3s+ num4s)/2)*100)/NumRows' THIS IS TURN %
EARLYSPEED= (TURN +BREAK)/2 'THIS IS THE OVERALL AVERAGE EARLYSPEED GIVING TURN 25% BENIFIT OVER BREAK
'DDART= (time6-time12)'beaten lengs
STRETCH=(num5s+ num6s)
FINISH=(num7s+ num8s)' FIN %
LATESPEED= (STRETCH +FINISH)'LATESPEED IS STR AND FIN'S SUM SMALLER THEN 3
print tab(10); "AvArt "; using( "##.##", time12 /5);" ";
print tab(50); "BREAK ";" TURN ";" STR ";" FIN% "
print tab(50); using( "##.#", BREAK);"   ";
print tab(53); using( "##.#",TURN);" ";
print tab(60); using( "##.#",((STRETCH*100)/NumRows)/2);" ";
print tab(62); using( "##.#",((FINISH*100)/NumRows)/2);" "
'print tab(0); "AvComp "; using( "##.##", time6 /5);


Print tab(5); "WIN% "; using( "##.##",(FINISH*100)/NumRows);" ";
'print tab(15); "Lngs "; using( "##.##", DDART /5 /.07);

print tab(50); "ELY " ;using( "##.##", EARLYSPEED);" ";
print tab(66); "LT ";using( "##.##", LATESPEED);" "

print "-------------------------------------------------------------------------"
' goto [again]



sub printSized i$, paddedLength, dirn$
if instr( i$, "/") then i$ =formattedDate$( i$)
if dirn$ ="R" or dirn$ ="" then
i$ =right$( space$( paddedLength) +i$, paddedLength) +" "
else
i$ =left$( i$ +space$( paddedLength), paddedLength) +" "
end if
print i$;
end sub

function formattedDate$( i$)

y$ =right$( "0000" +word$( i$, 3, "/"), 4)+"/"
m$ =right$( "00" +word$( i$, 1, "/"), 2)+"/"
d$ =right$( "00" +word$( i$, 2, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+m$+d$

end function

END
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5543
xx Re: sort routine tune-up-needed
« Reply #8 on: Oct 10th, 2017, 11:06am »

You still donít have the sort command set out as I showed you, you have the sort starting from the last record.

The command is SORT array$(),starting position ie 1, end position ie numrecords_1, followed by the column to sort on.
User IP Logged

debluzz
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 133
xx Re: sort routine tune-up-needed
« Reply #9 on: Oct 11th, 2017, 02:51am »

thanks again Rod,,,

ok, got all the sort's to sort as they should.

In the process I screwed up a couple of my (avg.totals)

avg comp & avg art

I was using: time6=0 & time12=0, it's been awhile since messed with.
here is a working copy which runs like a fine machine with no avgcomp or avgart
Code:

mainwin 100 22

filedialog "Open", "*.txt", file$
if file$ ="" then end

NumRows =0

open file$ for input as #f
notice "DONE w/SORTING"+"        "+"SAVE IN CAPS ONLY.... DOGG...."
while not( eof( #f))
line input #f, dummy$
if dummy$ <>"" then NumRows =NumRows +1 ' find how many rows ( 'NumRows') of data
wend

close #f

dim colWidth( 11), colAlign$( 11) ' hold desired column width and alignment L(eft) or R(ight)

colWidth( 0) =22: colAlign$( 0) ="L" ' Name
colWidth( 1) =10: colAlign$( 1) ="R" ' Date
colWidth( 2) = 2: colAlign$( 2) ="R" ' Grade
colWidth( 3) = 2: colAlign$( 3) ="R" ' Weight
colWidth( 4) = 5: colAlign$( 4) ="R" ' Comp
colWidth( 5) = 1: colAlign$( 5) ="L" ' bx
colWidth( 6) = 1: colAlign$( 6) ="R" ' br
colWidth( 7) = 1: colAlign$( 7) ="R" ' tr
colWidth( 8) = 1: colAlign$( 8) ="R" ' str
colWidth( 9) = 1: colAlign$( 9) ="R" ' fn
colWidth( 10) = 5: colAlign$( 10) ="R" ' Art
colWidth( 11) =22: colAlign$( 11) ="L" ' Com

print "Found "; NumRows; " rows "
'dim r$( NumRows, 11) ' NB indexes start at ZERO, so 0...11 is columns 1 to 12.
dim r$( NumRows , 11) ' This seems to sort it. WHYhuh
cls
open file$ for input as #inFile

for j =0 to NumRows -1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
[skip]
next j

close #inFile

print "Data check. "; "Found "; NumRows; " rows of data."
for j =0 to 11
call printSized r$( 0, j), colWidth( j), colAlign$( j)
next j
print

open file$ for input as #inFile

for j =0 to NumRows-1
line input #inFile, row$
if eof( #inFile) <>0 then exit for ' all data read
if row$ ="" then [skip] ' ( allow for the blank lines) ' ... but first word$( uses index 1 not zero..
for k =0 to 11
r$( j, k) =word$( row$, k +1, chr$( 9))
next k
'we now have the date string in r$(j,2)
'extract the year
y$ =right$( "0000" +word$( i$, 4, "/"),5)+"/"
d$ =right$( "00" +word$( i$, 2, "/"), 2)+"/"
m$ =right$( "00" +word$( i$, 2, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+d$+m$
[skip1]
next j

close #inFile

cls
column=1     'field 1 is the date
 print "Sort DATE field# "; column; "        CURRENT "
'sort r$(), ( NumRows),0, column ' arrayName, startRow, EndRow,
'Sort r$(),NumRows-1,1,1
sort r$(),( NumRows-1 ), 0,  1 '   arrayName, startRow, EndRow, ColumnForSortOrder
time6 =0: time12 =0
for i =0 to 6
for j =0 to 11
call printSized r$( i, j), colWidth( j), colAlign$( j)
if j = 6 then time6 =time6 +val( r$( i, j))
if j =10 then time12 =time12 +val( r$( i, j))
next j
print
next i
print
'end if
 column=10
    print: print "Sort FINISH for POST field# "; column; ".          TOP BOX's "

    sort r$(),0,NumRows -1,10'   arrayName, startRow, EndRow, ColumnForSortOrder
    time6 =0: time12 =0
    for i =1 to 5
       for j =0 to 11
           call printSized r$( i, j), colWidth( j), colAlign$( j)
           if j =6 then time6  =time6  +val( r$( i, j))
           if j =11 then time12 =time12 +val( r$( i, j))
       next j
       print
    next i
 print
'end if


 column=11
    print: print "Sort TIME field# "; column; ".                                 TOP TIMES "

    sort r$(), 1,  NumRows-1 , column-1 '   arrayName, startRow, EndRow, ColumnForSortOrder
    time6 =0: time12 =0
    for i =0 to 4
       for j =0 to 11
           call printSized r$( i, j), colWidth( j), colAlign$( j)
           if j = 6 then time6  =time6  +val( r$( i, j))
          if j =11 then time12 =time12 +val( r$( i, j))
       next j
       print
    next i
 print
'end if
'next x
' <<<< Routine to count 1's / 2's in column 7 (whole file? or in top fivehuh)>>>>>>>>>>>>>>>>>
num1s =0: num2s =0: num3s =0: num4s =0: num5s =0: num6s =0: num7s =0: num8s =0
for j =0 to NumRows -1 ' in whole file
' for j =0 to 4 ' in chosen top 5

col6 =val( r$( j, 6))
col7 =val( r$( j, 7))
col8 =val( r$( j, 8))
col9 =val( r$( j, 9))
'EARLY
if col6 =1 then num1s =num1s +1 'BREAK 1ST'S
if col6 =2 then num2s =num2s +1 'BREAK 2ND'S
if col7 =1 then num3s =num3s +1 'TURN 1ST'S
if col7 =2 then num4s =num4s +1 'TURN 2ND'S

'LATE
if col8 =1 then num5s =num5s +1 'STRETCH 1ST'S
if col8 =2 then num6s =num6s +1 'STRETCH 2ND'S
if col9 =1 then num7s =num7s +1 'FINISH 1ST'S
if col9 =2 then num8s =num8s +1 'FINISH 2ND'S
next j
'*************************EARLY
BREAK=(((num1s+ num2s)/2)*100)/NumRows'; THIS IS BREAK %
TURN= ((( num3s+ num4s)/2)*100)/NumRows' THIS IS TURN %
EARLYSPEED= (TURN +BREAK)/2 'THIS IS THE OVERALL AVERAGE EARLYSPEED GIVING TURN 25% BENIFIT OVER BREAK
'DDART= (time6-time12)'beaten lengs
STRETCH=(num5s+ num6s)
FINISH=(num7s+ num8s)' FIN %
LATESPEED= (STRETCH +FINISH)'LATESPEED IS STR AND FIN'S SUM SMALLER THEN 3
print tab(8); "AvArt "; using( "##.##", time12) ;" ";
print tab(50); "BREAK ";" TURN ";" STR ";" FIN% ";"vs ";NumRows;" LINES"
print tab(50); using( "##.#",BREAK);"   ";
print tab(53); using( "##.#",TURN);" ";
print tab(60); using( "##.#",((STRETCH*100)/NumRows)/2);" ";
print tab(62); using( "##.#",((FINISH*100)/NumRows)/2);" "
print tab(8); "AvComp "; using( "##.##", time6 );"   "
Print tab(8); "WIN% "; using( "##.##",(FINISH*100)/NumRows);" ";
'print tab(15); "Lngs "; using( "##.##", DDART /5 /.07);

print tab(50); "ELY " ;using( "##.##", EARLYSPEED);" ";
print tab(66); "LT ";using( "##.##", LATESPEED);" "

print "-------------------------------------------------------------------------"
' goto [again]



sub printSized i$, paddedLength, dirn$
if instr( i$, "/") then i$ =formattedDate$( i$)
if dirn$ ="R" or dirn$ ="" then
i$ =right$( space$( paddedLength) +i$, paddedLength) +" "
else
i$ =left$( i$ +space$( paddedLength), paddedLength) +" "
end if
print i$;
end sub

function formattedDate$( i$)
y$ =right$( "0000" +word$( i$, 3, "/"),4)+"/"
d$ =right$( "00" +word$( i$, 1, "/"), 2)+"/"
m$ =right$( "00" +word$( i$, 2, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+d$+m$ 
end function

END




 

« Last Edit: Oct 11th, 2017, 06:22am by debluzz » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5543
xx Re: sort routine tune-up-needed
« Reply #10 on: Oct 11th, 2017, 06:21am »

Here is some runnable code. I have not got a tab delimited file so this example use the space character to split the file up, the description at the end is lost but this does not matter for the demo.

I have also changed the code to use index 1-12. I just wonder if the zero index was causing confusion.

The date formatting is altered to eliminate the /

Code:
open "test.txt" for output as #1
#1 "XXXYYYYYYYYYYYY 6/27/2017 B 73 29.95 5 5 5 3 3 30.02 Got Busy Far, Rail"
#1 "XXXYYYYYYYYYYYY 6/22/2017 C 73 29.96 6 7 4 2 1 29.96 Tngld 1st, Arrived"
#1 "XXXYYYYYYYYYYYY 6/16/2017 C 73 30.53 2 8 7 6 3 30.86 All Hustle, Midtrk"
#1 "XXXYYYYYYYYYYYY 6/10/2017 B 73 30.18 5 7 8 6 5 30.34 Cautious 1st Turn"
#1 "XXXYYYYYYYYYYYY 6/5/2017 B 72 29.87 6 6 8 6 6 30.77 Jmd Rush, Inside"
#1 "XXXYYYYYYYYYYYY 6/1/2017 B 72 29.93 4 6 7 5 5 30.49 Tngld Rush, Blkd Far"
#1 "XXXYYYYYYYYYYYY 7/1/2017 B 73 29.58 1 6 5 5 4 29.99 Misstep Bckstr, Ins"
#1 "XXXYYYYYYYYYYYY 7/6/2017 B 72 29.78 2 7 4 2 2 29.8 All Drive, Bidding"
#1 "XXXYYYYYYYYYYYY 7/9/2017 B 72 29.45 2 6 7 7 5 30.57 Coll 1st Turn, Ins"
#1 "XXXYYYYYYYYYYYY 7/14/2017 B 73 29.96 3 5 6 6 5 30.47 Minor Late Moves"
#1 "XXXYYYYYYYYYYYY 7/19/2017 B 72 30.07 3 8 6 6 2 30.57 Late Speed For Place"
#1 "XXXYYYYYYYYYYYY 7/23/2017 B 72 29.98 4 3 4 4 4 30.42 Blkd Far Tn, Inside"
#1 "XXXYYYYYYYYYYYY 7/29/2017 B 72 29.95 3 3 8 8 7 30.59 Gave Way 1st, Inside"
#1 "XXXYYYYYYYYYYYY 8/4/2017 B 72 30.1 7 7 3 3 2 30.26 Late Surge For Plc"
#1 "XXXYYYYYYYYYYYY 8/8/2017 B 72 29.62 1 7 8 8 8 30.45 Gave Way 1st, Faded"
#1 "XXXYYYYYYYYYYYY 8/21/2017 B 71 30.39 4 7 8 6 5 30.68 Coll Erly, Blkd Far"
#1 "XXXYYYYYYYYYYYY 8/26/2017 B 72 29.49 7 7 7 8 8 30.7 Bmpd Rush, Faded"
#1 "XXXYYYYYYYYYYYY 9/1/2017 C 72 29.92 1 1 1 1 1 29.92 Up And Gone Inside"
#1 "XXXYYYYYYYYYYYY 9/6/2017 B 71 30.09 8 8 6 6 6 30.83 Trbl 1st, Faded Bck"
#1 "XXXYYYYYYYYYYYY 9/19/2017 B 72 29.85 2 5 8 8 7 30.52 Not A Threat, Ins"
#1 "XXXYYYYYYYYYYYY 9/23/2017 B 72 29.76 6 6 7 7 7 30.66 Gave Way 1st, Ins"
#1 "XXXYYYYYYYYYYYY 9/28/2017 C 71 30.35 1 4 5 2 1 30.35 Major Late Moves"
#1 "XXXYYYYYYYYYYYY 10/2/2017 B 71 30.56 1 3 6 7 4 30.9 Blkd 1st, Late Speed"
#1 "TTTTTRRRRRRRRRR 6/30/2017 C 76 30.12 4 5 2 1 1 30.12 Just In Time, Mid"
#1 "TTTTTRRRRRRRRRR 7/5/2017 B 76 29.92 4 1 1 1 1 29.92 Never Looked Back"
#1 "TTTTTRRRRRRRRRR 7/10/2017 A 76 29.83 4 8 2 3 4 30.24 Mild Drive, Inside"
#1 "TTTTTRRRRRRRRRR 7/15/2017 A 77 30.06 1 3 1 1 1 30.06 Late Push For Win"
#1 "TTTTTRRRRRRRRRR 7/21/2017 A 76 29.88 5 5 4 3 4 30.49 Rough Trip, Midtrk"
#1 "TTTTTRRRRRRRRRR 7/26/2017 A 76 29.59 7 3 1 1 3 29.95 Brief Lead, Tiring"
#1 "TTTTTRRRRRRRRRR 7/31/2017 A 76 29.8 6 7 2 2 3 30.13 Caught Late, Inside"
#1 "TTTTTRRRRRRRRRR 8/5/2017 A 76 29.83 5 1 1 1 1 29.83 Led Every Step, Ins"
#1 "TTTTTRRRRRRRRRR 8/11/2017 A 77 29.83 8 8 1 1 8 30.32 Led, Out Of Gas"
#1 "TTTTTRRRRRRRRRR 8/17/2017 A 76 29.7 6 1 1 1 2 29.74 Overtaken Late, Mid"
#1 "TTTTTRRRRRRRRRR 8/24/2017 A 77 29.65 3 2 4 7 8 30.75 Erly Gain, Faded Lt"
#1 "TTTTTRRRRRRRRRR 9/4/2017 A 77 29.89 7 4 2 3 5 30.62 Lost Grnd Far Turn"
#1 "TTTTTRRRRRRRRRR 9/18/2017 A 76 29.98 6 5 3 3 4 30.7 Erly Bid, Outdrove"
#1 "TTTTTRRRRRRRRRR 10/2/2017 B 76 30.56 2 4 2 3 7 31.11 Coll 1st, Lost Grnd"
close #1

'count the number of filled rows
open "test.txt" for input as #1
NumRecords=0
while not( eof( #1))
    line input #1, dummy$
    if dummy$ <>"" then NumRecords =NumRecords +1
wend
close #1
NumFields=12

dim colWidth(NumFields), colAlign$(NumFields) ' hold desired column width and alignment L(eft) or R(ight)
colWidth( 1) =22: colAlign$( 1) ="L" ' Name
colWidth( 2) =10: colAlign$( 2) ="R" ' Date
colWidth( 3) = 2: colAlign$( 3) ="R" ' Grade
colWidth( 4) = 2: colAlign$( 4) ="R" ' Weight
colWidth( 5) = 5: colAlign$( 5) ="R" ' Comp
colWidth( 6) = 1: colAlign$( 6) ="L" ' bx
colWidth( 7) = 1: colAlign$( 7) ="R" ' br
colWidth( 8) = 1: colAlign$( 8) ="R" ' tr
colWidth( 9) = 1: colAlign$( 9) ="R" ' str
colWidth( 10) = 1: colAlign$( 10) ="R" ' fn
colWidth( 11) = 5: colAlign$( 11) ="R" ' Art
colWidth( 12) =22: colAlign$( 12) ="L" ' Com

print "Found "; NumRecords; " Records in file "
dim r$( NumRecords , NumFields)
open "test.txt" for input as #1
for r = 1 to NumRecords
    line input #1, rec$
    if rec$ ="" then [skip]
    for f =1 to NumFields
        if f=2 then
            r$(r,f)=formattedDate$(word$(rec$,f," "))
        else
            r$(r,f) =word$(rec$,f," ")
        end if
    next f
    [skip]
next r
close #1

'unsorted
for r = 1 to NumRecords
    for f = 1 to NumFields
        call printSized r$(r,f), colWidth(f), colAlign$(f)
    next f
    print
next r
print

sort r$(),NumRecords,1,2 'reverse order, sorted last to first,field 2 is now the date field

'sorted
for r = 1 to NumRecords
    for f = 1 to NumFields
        call printSized r$(r,f), colWidth(f), colAlign$(f)
    next f
    print
next r

wait




sub printSized i$, paddedLength, dirn$
    if dirn$ ="R" or dirn$ ="" then
        i$ =right$( space$( paddedLength) +i$, paddedLength) +" "
    else
        i$ =left$( i$ +space$( paddedLength), paddedLength) +" "
    end if
    print i$;
end sub

function formattedDate$(i$)
    y$ =right$( "0000" +word$( i$, 3, "/"), 4)
    d$ =right$( "00" +word$( i$, 2, "/"), 2)
    m$ =right$( "00" +word$( i$, 1, "/"), 2)
    formattedDate$ =y$+m$+d$
end function

 



If you are still having trouble be sure to print out the r$(r,f) array especially the date field to see what you are actually sorting on.
« Last Edit: Oct 11th, 2017, 06:25am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5543
xx Re: sort routine tune-up-needed
« Reply #11 on: Oct 11th, 2017, 1:11pm »

Well I am glad that you are seeing some progress. This is your most recent formattedDate$() function.

There are two mistakes, can you see them? They cancel each other out surprisingly.

Code:
function formattedDate$( i$)
y$ =right$( "0000" +word$( i$, 3, "/"),4)+"/"
d$ =right$( "00" +word$( i$, 1, "/"), 2)+"/"
m$ =right$( "00" +word$( i$, 2, "/"), 2)
p =instr( i$, "/")
formattedDate$ =y$+d$+m$ 
end function

 



To order a date you must list it as year,month,day.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls