Hi folks
Im having an issue converting an actual date to a single day value correctly
In the code provided I fill random dates in, convert the date into a single day value, quicksort the results then proceed to bring the data to screen
On line 27 there is a remmed out item of code - if unremmed you will see the coversion works well enough for the year order when executed, so I beleive my error is in miscalculating the day value of months and days
If executed as-is, you can see results produced are incorrect - different dates when converted are the same result when they clearly shouldnt be. Unfortunately I am taking medication that affects how I think(a very recent course Ive started after writing the bulk of a larger program), so for the life of me I cannot see where I went wrong! In fact Ive mulled over the code now for several days..
Please note this code is part of a much larger program so variable names may not conform exactly as you might expect but I believe are named well enough for simple understanding
Hope someone here can help me out asap;
set window on
set display mode 1024,768,32
dim year(1000,1)
dim months(12,1)
dim eventsortbydateone(1000,1,1)
dim eventsortbydatetwo(1000,1)
months(1,1)=31
months(2,1)=28
months(3,1)=31
months(4,1)=30
months(5,1)=31
months(6,1)=30
months(7,1)=31
months(8,1)=31
months(9,1)=30
months(10,1)=31
months(11,1)=30
months(12,1)=31
`enter years and flag leap years(does not yet account for leap-nonleap-leapyears)
yer=4
for t=0 to 1000
year(t)=t+2000
if yer=4 then year(t,1)=1 : yer=0
yer=yer+1
next t
for t=1 to 1000
eventsortbydateone(t)=2001 `+rnd(999)
eventsortbydateone(t,1)=1+rnd(11)
eventsortbydateone(t,1,1)=1+rnd(28)
gosub daynum
next t
quicksort(1,1000)
`mainloop
do
omz=mz
mz=mousez()
cls 0
set cursor 0,0
gosub events
loop
events:
for ty=1 to 15
center text 512,(ty*40)+8,str$(eventsortbydateone(evpage*15+ty,1,1))+"/"+str$(eventsortbydateone(evpage*15+ty,1))+"/"+str$(eventsortbydateone(evpage*15+ty))
center text 512,(ty*40)+24,str$(eventsortbydatetwo(evpage*15+ty))
next ty
print evpage
if omz>mz
evpage=evpage-1
endif
if omz<mz
evpage=evpage+1
endif
if evpage<0 then evpage=0
if evpage>65 then evpage=65
center text 512,10,"Jobs"
return
daynum:
daysthisyear=0
`yr
currentyear=eventsortbydateone(t)
`mnth
currentmonth=eventsortbydateone(t,1)
`dy
currentday=eventsortbydateone(t,1,1)
`num of leap years
leapyears=floor((currentyear-2001)/4)
`num of yrs total
totalyears=currentyear-2001
`num of common years
commonyears=totalyears-leapyears
`num of days of leap years
leapdays=leapyears*366
`num of days of common years
commondays=commonyears*365
`num days of current year
gosub isleapyear
repeat
fg=fg+1
daysthisyear=daysthisyear+months(fg,1)
until currentmonth=fg
daysthisyear=daysthisyear-months(fg,1)
`total num days since beginning 2001
totaldays=daysthisyear+currentday+leapdays+commondays
fg=0
eventsortbydatetwo(t)=totaldays
return
isleapyear:
if year(totalyears,1)=1
months(2,1)=29
else
months(2,1)=28
endif
return
function quicksort(lo,hi)
sorted = 0
while sorted = 0
sorted = 1
for a=lo to hi-1
if eventsortbydatetwo(a) > eventsortbydatetwo(a+1)
h = eventsortbydatetwo(a) : eventsortbydatetwo(a)=eventsortbydatetwo(a+1) : eventsortbydatetwo(a+1)=h : sorted = 0
h = eventsortbydateone(a) : eventsortbydateone(a)=eventsortbydateone(a+1) : eventsortbydateone(a+1)=h
endif
next a
endwhile
endfunction