|
Post by joethebow on Feb 10, 2009 18:13:59 GMT
I'm using a label printer that's programmed in Basic using MS Hyperterminal, no major problem as I was brought up on BASIC.
My only real problem is the date. I need to print a best before date on the labels.
If I print date$ for today I get 090210
OK using Left$ & right$ I can separate them out and print them as: 10 02 09. so far so good.
I can then convert the strings to numbers using VAL and when I print them I get 10 2 9, still no problem
Now I need to add either 3 14 or 28 days depending on the product labeled. Now you're beginning to see the problem.
Can't have 38 02 09 can we?
So I need a way to add 3 14 or 28 days to the date anmd still have a valad date. I've wrecked my brains for days but haven't come up with a solution that doesn't require a couple hundred lines of code.
Currently I have a fudge in that the PC which drives the labeling machine prints todays date on the screen and asks me for the label's date. It's OK but I need to do all the 3 day products first, then the 14 and finally the 28. I also have to remember to change the date! It works but I'd like something a bit more elegant.
|
|
|
Post by Mikrondel on Feb 13, 2009 8:08:48 GMT
The only real trick is leap years.
This code is more or less what you want. It should be able to handle any number of days. Adjust to taste.
DIM DaysInMonth(1 TO 12) AS INTEGER DaysInMonth(1) = 31 DaysInMonth(2) = 28 DaysInMonth(3) = 31 DaysInMonth(4) = 30 '... etc. ...
Day = ... Month = ... Year = ...
'Leap years IF (Year MOD 4) = 0 THEN DaysInMonth(2) = 29 ELSE DaysInMonth(2) = 28
Day = Day + 3 'Or any value, really
WHILE Day > DaysInMonth(Month) Day = Day - DaysInMonth(Month) Month = Month + 1 IF Month > 12 THEN Year = Year + 1 Month = 1 'The next line isn't technically necessary if you add less than 59 days IF (Year MOD 4) = 0 THEN DaysInMonth(2) = 29 ELSE DaysInMonth(2) = 28 END IF WEND
|
|
clippy
Junior Member
Posts: 32
|
Post by clippy on Feb 24, 2009 18:38:13 GMT
Leap years calculation is wrong! You need to check for century leap years. Every 400 years is a leap year also.
So year MOD 400 = 0 to find those leap years. The other 300 are NEVER leap years!
Will DOS and QB still be around? LOL
|
|