by Michael Pesach
| In November 1998, Gary Smith came to the NY Alpha Users Group meeting and demonstrated his calendar utility, to the immense appreciation of all present. Gary's calendar was truly a pioneering development. Michael Pesach, a member of the NY AUG (e-mail address: Ifomatic@aol.com) has leveraged his skills in Alpha Five to modify and trim Gary's design. |
First, we need to figure how many weeks we will need to cover any given month.
Figure1. Calendar form
I name the buttons in one convention, calling each button "B01", "B02", .... "B42":

Figure 2. Design of calendar.
I have 3 global variables that are set at different times:
The whole program runs on 2 small scripts:
Script 1. Monthchange (the line numbers are for reference and should not appear in your Xbasic)
''XBasic
1.dim global prev_butt as c
2.dim shared startnum as n
3.dim shared startdate as d
4.dim runnum as c
5.dim shared listing[42] as c
6.dim i as n
7.dim currentday as c
8.startdate = ctod(padl(alltrim(str(month(showdate))),2,"0")+"/01/"+alltrim(str(year(showdate))))
9.startnum = dow(ctod(padl(alltrim(str(month(showdate))),2,"0")+"/01/"+alltrim(str(year(showdate)))))
10.FOR i = 1 to 42 step 1
11. runnum = padl(alltrim(str(i)),2,"0")
12. eval("B"+runnum+".text") = alltrim(str(day(startdate-startnum+i)))
13. listing[i] = dtoc(startdate-startnum+i)
14. if month(startdate-startnum+i) = month(startdate)
15. eval("B"+runnum+".font.color") = "red"
16. else
17. eval("B"+runnum+".font.color") = "blue"
18. end if
19.NEXT
20.parent.resynch()
This script kicks in whenever you would change the month of the focus date and when you start the form.
We need to set the start date for the form's OnInit event as follows:
1.dim global showdate as d
2.showdate=date()
3.script_play("monthchange")
This script simply sets the showdate variable to the current date so we have something to start with. Then it goes on to run our monthchange script that will set all the diplays on the buttons to show correctly for this month.
Line 8: we must get the date of the first of the month so that we could get the day of week. So we string out the show date and take off the last 2 digits (that is today's date) and we replace that with "01" for the 1st of the month.
Line 9: we use the DOW function to get the day of the week of the first of the month. Now we know which button we want "1" to display for the first of the month.
Line 10: we run a loop to go through all the buttons. Remember we had 42 that we named B01 to B42 respectively.
Line 11: We need the number of the button we are going to set the text to so we take i which is the number of the button we are up to. We then string it and make sure it is 2 digits using the PADL function.
Line 12. Then we use the eval function to have xbasic interpret our small function to correspond to a button on our form. And we set the text of the button to the day of month of the startdate variable plus the startnum variable plus the variable that tells us which button we are up to. This would work even for buttons of the next month since this will calculate a date, not a day or month.
Line 13. We need an array for the button action scripts so that each button has a date connected to it so when we push it we know what date we are going to.
Lines 14,15,16,17,18. These lines are for cosmetics only. We have the current month showing in red and the previous and next month showing in blue. So we check if the button is in the current month (showdate) we set it to red and if it not we set it to blue.
Line 19. Move to the next button.
Line 20. Redisplays the entire form.
Script 2. button ac script.
''XBasic 1. dim shared listing[42] as c 2. dim shared startdate as d 3. dim global showdate as d 4. showdate = ctod(listing[val(substr(this.object.name,2,2))]) 5. showdate.refresh()
This script just sets the showdate variable to the corresponding value in the array that we created in the monthchange script. And then we refresh the showdate on the screen we do not have to refresh the entire screen or update anything else since we did not change months. New we attach the button ac script to all the dates on the calendar:
Figure 3. Each button has the same button ac OnPush script.
And we add the following script to the right-month button to change the month forward one month:
''XBasic
dim global showdate as d
showdate = addmonths(showdate,1)
script_play("monthchange")
last revised 1/22/99 - pkw
Don't forget, we need your feedback to make this site better!