Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Simplifying Date Data Entry with Calendars, Part I-4 : Page 4


advertisement
Writing the GenerateCalendar Routine
In order to output the calendar dates, iterate a variable from one to 42 (six rows of seven columns each). Use the following code to output the calendar:

Sub GenerateCalendar() Dim i ' -- Row begin Response.Write "<TR>" & vbCrLf ' -- Left blank column Response.Write "<TD> </TD>" & vbCrLf ' -- Dump all the days For i = 1 to 42 ' -- is it before the beginning of the month If i < intFDay Then ' -- write a blank WriteInActiveCalDay " " ' -- Is it after the end of the month ElseIf i > intNoDays + intFDay - 1 Then ' -- Write a blank WriteInActiveCalDay " " Else ' -- Write the day WriteActiveCalDay (i- intFDay +1) End If ' -- Do we need to go to the next row? if i Mod 7 = 0 Then ' -- we are at the end of the week ' -- Right blank column Response.Write "<TD> </TD>" & vbCrLf ' -- End of the Row Response.Write "</TR>" & vbCrLf ' -- Do we need another row? If i <= intNoDays + intFDay - 1 Then ' -- Row begin Response.Write "<TR>" & vbCrLf ' -- Left blank column Response.Write "<TD> </TD>" & vbCrLf Else ' -- we have exceeded the number of days, get out Exit For End if End if Next ' -- End the row if i Mod 7 <> 0 Then Do While i Mod 7 > 0 WriteInActiveCalDay " " i = i+1 Loop ' -- Right blank column Response.Write "<TD> </TD>" & vbCrLf ' -- End of the Row Response.Write "</TR>" & vbCrLf End if End Sub

First, output the row beginning and the left blank column:

' -- Row begin Response.Write "<TR>" & vbCrLf ' -- Left blank column Response.Write "<TD> </TD>" & vbCrLf

Now iterate from one to 42 using a For loop. Check to see if the value of "i" is less than the beginning of the month. If it is, output a blank cell by using the routine "WriteInactiveCalDay." Similarly, if the value of "i" is greater than the last day of the month (factored appropriately), you'll again output a blank cell. Otherwise, output the day of the month using the routine "WriteActiveCalDay" passing the date to be outputted. When you have reached the end of the week (seventh day), skip to the next line by finishing the right blank column and row and then beginning a new row. Finally, if you have exceeded the number of days in the month, get out of the loop. Outside the loop, check to make sure you have not quit in the middle of the week. If you have, you need to go back and complete the week row.



The actual task of outputting a day is handled by the routines WriteInactiveCalDay and WriteActiveCalDay. The difference in these routines is the presence or absence of a hyperlink that, when clicked, will update the text box in the date field you set out to fill. This is the code for the routines.

Sub WriteInActiveCalDay(byval sLabel) Response.Write "<TD WIDTH=""20"" ALIGN=""CENTER"" VALIGN=""TOP"">" & sLabel & "</TD>" & vbCrLf End Sub '------------------------------------------------------ Sub WriteActiveCalDay(byval sLabel) Response.Write "<TD WIDTH=""20"" ALIGN=""CENTER"" VALIGN=""TOP""> <A HREF=""BLAH"">" & sLabel & "</A></TD>" & vbCrLf End Sub

Save your work and check the page in your browser. You should get a fully functional calendar page with hyperlinks. You can check this out in action as well as download the entire code for this article here.

For now, we are outputting a hyperlink that says "blah." The links are not operational so don't click on them. Next month I'll show you how to change the hyperlink to perform some action and to show you how to tie your calendar page to the data entry page. Until next time, good luck.



Rama Ramachandran is the Vice President of Technology with Imperium Solutions and is a Microsoft Certified Solution Developer and Site Builder. He has extensive experience with building database systems and has co-authored several books including "Professional Visual InterDev 6 Programming" and "Professional Data Access" (Wrox). Rama teaches Visual Basic and Web development at Fairfield University and University of Connecticut.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date