Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Completing Calendars with VBScript Date Fu...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Completing Calendars with VBScript Date Functions
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-02-02

    Table of Contents:
  • Completing Calendars with VBScript Date Functions
  • Building the array
  • Completing the code
  • Validating user input

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Completing Calendars with VBScript Date Functions - Building the array


    (Page 2 of 4 )

    Now I can create a loop to add the correct number of empty values to the beginning of my array.  I’m just adding spaces as strings.  You can see the columns in my example output allow three spaces to display a given date.  I’m also padding that with three leading spaces to space out my columns a little more and make it look pretty.  So each empty date should contain a string of six spaces.

       For i = 1 To intDaysInMonth

           ReDim Preserve arrMonth(UBound(arrMonth) + 1)

           strDay = CStr(i)

           intPad = 6 - Len(strDay)

           strDay = Space(intPad) & strDay

           arrMonth(UBound(arrMonth)) = strDay

       Next

    Next I add the individual days of the month to my array by looping through each value between 1 and the last day of the month.  Notice again that I’m padding each value as necessary so that each date string contains six characters.

       intEmptyDays = 7 - intLastWeekDay

       For i = 1 To intEmptyDays

           ReDim Preserve arrMonth(UBound(arrMonth) + 1)

           arrMonth(UBound(arrMonth)) = "      "

       Next

    Once all the dates are in place, I’m finding the number of empty days at the end of the month.  This is done by taking the highest possible weekday, 7 for Saturday, and subtracting the weekday of the last day in the month.  These are added to the array as strings of spaces as before.  Adding these empty days ensures that our array contains complete weeks.

       BuildArray = arrMonth

    End Function

    Finally, an array of complete weeks for our given month is returned to the main script.

    Back in our main script, we’re ready to begin displaying the calendar.

    WScript.Echo "  ", MonthName(intMonth), intYear

    WScript.Echo ""

    WScript.Echo "   Sun", "   Mon", "   Tue", "   Wed", "   Thu", "   Fri", "   Sat"

    A few lines are used to set up the basic look by providing the month and year titles and well as the weekday headers for our table.

    For i = 0 To UBound(arrThisMonth) Step 7

       WScript.Echo arrThisMonth(i), arrThisMonth(i + 1), arrThisMonth(i + 2), arrThisMonth(i + 3), arrThisMonth(i + 4), arrThisMonth(i + 5), arrThisMonth(i + 6)

    Next

    Next, we rely on a For loop to move through the values in our array of days.  We want to return them in one-week intervals so that each week can be printed on a new line.  To do this we simply move through the entire array with a Step value of 7, essentially reading seven values at a time.  Then it’s just a matter of printing each of those seven values on a single line.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek