Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - 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 - Completing the code


    (Page 3 of 4 )

    At this point we have a complete working script.  If you would like to learn how to add validation to this code, be sure to continue on to the next page.  In the meantime, here’s what the completed script currently looks like:

    If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then

        strPath = WScript.ScriptFullName

        strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34)

        CreateObject("WScript.Shell").Run(strCommand)

        WScript.Quit

    End If

     

    strDate = InputBox("Please enter a month and year as MM/YYYY.", "Microsoft Scripting Games 2008")

    If strDate = "" Then WScript.Quit

     

    arrDateParts = Split(strDate, "/")

    intMonth = arrDateParts(0)

    intYear = arrDateParts(1)

     

    dteFirstDay = DateSerial(intYear, intMonth, 1)

    intFirstWeekDay = WeekDay(dteFirstDay)

    intDaysInMonth = DaysInMonth(intMonth, intYear)

    intLastWeekDay = WeekDay(DateSerial(intYear, intMonth, intDaysInMonth))

     

    arrThisMonth = BuildArray()

     

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

    WScript.Echo ""

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

    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

     

    Function BuildArray()

       arrMonth = Array()

       intEmptyDays = intFirstWeekDay - 1

       For i = 1 To intEmptyDays

           ReDim Preserve arrMonth(UBound(arrMonth) + 1)

           arrMonth(UBound(arrMonth)) = "      "

       Next

     

       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

     

       intEmptyDays = 7 - intLastWeekDay

       For i = 1 To intEmptyDays

           ReDim Preserve arrMonth(UBound(arrMonth) + 1)

           arrMonth(UBound(arrMonth)) = "      "

       Next

     

       BuildArray = arrMonth

    End Function

     

    Function DaysInMonth(intMonth, intYear)

       If intMonth = 12 Then

           dteNextMonth = DateSerial(intYear + 1, 1, 1)

       Else

           dteNextMonth = DateSerial(intYear, intMonth + 1, 1)

       End If

     

       DaysInMonth = DateDiff("d", dteFirstDay, dteNextMonth)

    End Function

    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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek