May 11, 2024, 07:17:34 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


I am writing a Calendar Printing Program for a Friend

Started by billhsln, December 07, 2008, 04:43:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

However the problem seems to be that what I display on the screen, which I want printed in Landscape exactly as what is shown on the window.  What I end up with is centered on the page and on the upper half of the page.  Is there some parameter that I need to set?

This is not the completed program only a shell created to see where things end up on the screen and printer.  I am defaulting to January 2009, there is a lot more code that needs to be done, but right now the main problem is not printing on the page in the way I need.

/*  Compile as Windows.exe

This program allows you to pick a Starting Year and Month and then prints Calendars

*/

$MAIN
DEF Version$:String
Version$="1.0"
AUTODEFINE "off"

DEF w1:WINDOW
DEF c, day, i, j, x, y:INT
DEF cFG, cBG:UINT
DEF day$:STRING
DEF FirstDay:INT
DEF pxy[7,6,2]:INT

' Constants
CONST cBLACK   = 0
CONST cCYAN    = 0x00FF901E
CONST cHIWHITE = 0x00FFFFFF
CONST cWHITE   = 0xFFFFFFFF

cFG = cBLACK
cBG = cWHITE

pxy[0,0,0] = 330
pxy[0,0,1] = 75

FOR i = 1 TO 5
pxy[i,0,0] = pxy[0,0,0] + (80 * i)
pxy[i,0,1] = 75
FOR j = 1 to 5
pxy[i,j,0] = pxy[i,0,0]
pxy[0,j,0] = pxy[0,0,0]
pxy[0,j,1] = pxy[0,j-1,1] + 80
pxy[i,j,1] = pxy[0,j-1,1] + 80
NEXT j
NEXT i

pxy[6,0,0] = pxy[5,0,0]
pxy[6,0,1] = 115

FOR i = 1 TO 5
pxy[6,i,0] = pxy[6,0,0]
pxy[6,i,1] = pxy[6,i-1,1] + 80
NEXT i

OPENWINDOW w1,0,0,792,612,0,0,"Print Calendars",&hnd

SETFONT w1,"Courier New",12,400,0,0
SETWINDOWCOLOR w1, cBG
FRONTPEN w1, cFG
BACKPEN w1, cBG

RECT w1,270,5,480,40
FOR i = 270 TO 710 STEP 80
RECT w1,i,45,80,30,cFG,cBG
FOR j = 10 TO 462 STEP 80
RECT w1,i,j + 65,80,80
RECT w1,670,j + 65,80,40
NEXT j
NEXT i

FRONTPEN w1, cCYAN
BACKPEN w1, cFG

SETFONT w1,"Tahoma",18,900,0

MOVE w1,440,8
PRINT w1,"January 2009"

SETFONT w1,"Arial",12,400,0

MOVE w1,295,50
PRINT w1,"Mon"

MOVE w1,375,50
PRINT w1,"Tue"

MOVE w1,455,50
PRINT w1,"Wed"

MOVE w1,540,50
PRINT w1,"Thu"

MOVE w1,620,50
PRINT w1,"Fri"

MOVE w1,680,50
PRINT w1,"Sat/Sun"

c = 0
FirstDay = 4
day = 1
FOR y = 0 TO 4
FOR x = 0 TO 6
c ++
MOVE w1,pxy[y,x,0],pxy[y,x,1]
IF c >= FirstDay
day$ = LTRIM$(STR$(day))
IF LEN(day$) < 2 THEN day$ = "_" + day$
PRINT w1, day$
day ++
IF day > 31 THEN BREAKFOR
ENDIF
NEXT y
NEXT x

PRINTWINDOW w1

WAITUNTIL w1 = 0

END

'======
SUB hnd
'======
'handler for the window w1
SELECT @CLASS
CASE @IDCREATE
CENTERWINDOW w1
CASE @IDCLOSEWINDOW
CASE& @IDDESTROY
CLOSEWINDOW w1
ENDSELECT
RETURN
ENDSUB


Thanks for any help,
Bill
When all else fails, get a bigger hammer.

JohnP

I experimented with your code because I had no knowledge of the printing system and was curious to learn more.
I also have a need to produce very plain and simple calendars for my mother who has macular degeneration and can barely see.

What I discovered was that, on the printout, the rectangle which bounds the calendar is in proportion to your screen's horizontal & vertical resolution.
In other words, the print is like a screen dump.

So I amended your code and introduced a couple of constants to hold the screen x & y resolution and added them into the code where the window is opened:


CONST screen_width = 1280
CONST screen_height = 1024
.....
.....
OPENWINDOW w1,0,0,screen_width,screen_height,@MINBOX|@MAXBOX|@SIZE,0,"Print Calendar",&main


Of course, I have scaled the grid to match the screen size. 
In fact I have tried to code automatic scaling for various screen resolutions, but auto text-sizing is hard.

That enabled me to print a landscape calendar grid which almost filled my A4-sized sheet.
Actually, my printer-driver doesn't let me set margins, and there is a slightly annoying wider right-margin over which I have no control.
But it does produce a useable, large clear printout.

I have extended your shell to print each month in turn and to also print short messages in the correct days for person's birthdays.
The messages are initially stored in DATA statements, hard-wired into the code, then read into a 3-D array (month,Day,up-to-3-messages-onthat-day).
It might be better to save the messages to an associated text-file so they can be edited outside the program (or use a list box, perhaps)

I plan to add date arithmetic code for Easter calculation, leap years, etc.

Maybe you have already solved your problem, but I hope this helps.

Thanks for sharing your code.  I've learned quite a bit from it.

JohnP

billhsln

John, from what you said it seems that you have it working exactly as I was trying to get it to work.  Could you put your revised code out here for every one to see?  I would like to see what you set up and how it works.

As to Date Routines, I wrote a set of subroutines that should solve your problem, see: http://www.ionicwind.com/forums/index.php/topic,2671.0.html

There are routines there to determine Easter, which moves around a lot and other things, like 4th Thursday of the Month for those holidays that are on a specific day/week of a month.

I know I would appreciate a copy of your revised calendar printing program, as would others.

Thanks,
Bill
When all else fails, get a bigger hammer.

JohnP

I'd be glad to share my code... it's mostly yours anyway!
The Easter sub-routine is right on target, thank you.  I'll certainly put that in.

But it does need tidying up a bit, so let me tie up some loose ends
I need to put in something to choose the year, too.

And the scaling stuff needs to be sorted at the extremes of screen size.

But I will get to it and won't polish it indefinitely!  Expect it before Christmas (2008).

regards
JohnP

JohnP

Bill,

Here, as promised, is my version of the simple calendar program.

There's lots to improve/add, so enjoy.

Happy Christmas to all.

JohnP

billhsln

December 22, 2008, 10:22:42 PM #5 Last Edit: December 22, 2008, 11:21:00 PM by billhsln
Thanks for uploading your revised code.

Here is the code you need to determine Thanksgiving.  The code is in my Date Routines.

' Fourth Thursday of November 2008 (Thanksgiving)
x = NthDayOfMonth(4, Thursday, 2008, 11)
print ISODate(2008,08,x), " is the Fourth Thursday of November 2008"

You will also need to change:

DEF mess[12,31]:STRING      'string array for month, day, but only 1 message per day
to
DEF mess[13,32]:STRING      'string array for month, day, but only 1 message per day
because of the way you are using this array.

Also, if I remember right, leap years are either divisible by 4 or 400, not 100, which would mean the 2100 is NOT a leap year, whereas 2000 is a leap year.

Thanks again for the revised code.

Bill

When all else fails, get a bigger hammer.

JohnP

Thanks for the Thanksgiving routine! 
I didn't spot it amongst your date sub-routines.  Very useful those are, too.

I think you are correct about the leap year.  I'll alter that right away.

Thanks also for pointing out my elementary error in using a zero-based array, but only using it starting from element no.1. 
It caused me to run out of array elements at the end of the month.
So that's why I got some strange messages like 'December' on 30 Dec and had to put a kludge in to prevent them being displayed. :-\
I can now remove that bit of code, if I use the array as you suggest.

I guess it would help users if the section of code dealing with messages was re-written to use an external text file instead of hard-coded data statements.
Then the user wouldn't need to access the code to personalise the messages; just the text file using, say, MS-Notepad.
Or, better yet, an editable, 3-column listbox which saves its contents to a file, so that it will persist?

Also, I though it would improve readability a little, if all Sat & Sun cells were lightly shaded?

regards
JohnP

tbohon

John:

Nice job!!!

I think your ideas - to put the messages in a simple .txt file, easily editable by the end user (maybe via a button in your gui? :-) ) and lightly shading weekends (and maybe holidays) would be great additions.

Again, nicely done my friend, nicely done.

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)