loading
Introduction
Have you ever wondered what the date and day of the week it would be in X number of days from today?  How many days there are from today to some future date?  How about the number of days between two dates? 

Lets look at some practical applications for a Date Calculator App.vbs:
What is the mature date of Fantastic tomatoes if they say 72 days? - I can not wait to eat a Fantastic tomato.
How many days until Flag Day? - Flag Day is an under recognized observance.
How many days from next pay day to vacation? - How many days do I have to save money for vacation?

Wouldn't you like to have an app like that?  Wait, wouldn't you like to create an app like that?  You could customize your own Date Calculator App.vbs

The Story
My wife will ask me what day of the week a certain date will be.  My kids ask me how long until vacation.  This morning my daughter asked me how many days until ......  I responded, "I do not know ,,,,,,,,,,,,,,,,,  I am going to create a program so you can answer the question yourself."   She thought that was, "Cooool."

Well, I started to think on it later.  The more I thought on it; the more I wanted to create this application.  I sat down at my computer and thought about what it should do, how should it look, how much time do I want to put into this application?  With these questions in my focus I also thought about other things.   I wanted the application to be something simple to use, something with easy to understand code and not a resource hog.  After a little more thinking this is what I came up with, read on to create your own Date Calculator App.vbs.

Because this is .vbs (Visual Basic Scripting) you will need a Windows based Operating System.

Objective:
The intent of this instructable is to
1)  Create a simple application capable of performing 3 different calculations.
2)  Share code to move beyond the "Hello World" message box to a dynamic interactive application.
3)  Motivate you to create other useful applications by showing how easy the code can be.

Step 1: Items Covered

In this instructable you will see:
1)  An Input box,
          An Input box is a way to respond to a question.  It could be something like entering a password or choosing between multiple options, as in the case before you today.
2)  A Message box,
          A Message box is a way to display a message and allow you to answer Yes, No, Cancel, Retry or Ignore.
3)  Select Case Statements,
          Select Case Statements tells the code what to do based upon the users input.
4)  Handle Errors and
          Error Handling is important when you move beyond the basic "Hello World" message box and start to have choices.  No one wants to see a popup error script.  Sometimes they are cryptic even to a seasoned programmer.
5)  How to Comment out notes in the code.
          Comment out notes is important.  It allows anyone to know what is going on at that point in the code.  The code will not run when the line is preceded by ' an Apostrophe.

Skill Level
Easy – if you copy and paste. 
Medium – if you want to change the code.

Time to Complete
5 – 10 minutes, more if you make changes.

Warning:  If you make the wrong change to the aforementioned code.  You could, at worst, ruin your day.   It is no fun chasing errors.  What I have learned is that it is usually a simple mistake.
Disclaimer:  Modify at your own risk.

Step 2: What Is the Date and Day in X Days?

This is what you will see when you enter "1" into the 1st Input box.

Step 3: Count the Number of Days

This is what you will see when you enter "2" into the 1st Input box.

Step 4: How Many Days Between 2 Dates?

This is what you will see when you enter "3" into the 1st Input box.

Step 5: Error Handling

This is what you will see when you enter something outside of the given parameters.

Error Handling is important when you move beyond the basic "Hello World" message box and start to have choices.  No one wants to see a popup error script.  Sometimes they are cryptic even to a seasoned programmer. (Notation) I am not a seasoned programmer.

Step 6: The Code

1)  Open the Notepad application:
Click Start => click Programs => click Accessories => click Notepad
Or

Click Start => Click Run => Type Notepad in the Run input box then Click OK.

2)  Copy the code below the Apostrophe and Asterisks line then Paste it into Notepad

' *********************************************

Dim Notice
Dim Message
Dim Message1
Dim Message2

'  Error Handling
On Error Resume Next

'  Standard Inputbox
Notice = "  My Date Counter "
Message = "What would you like to do ?" & vbcr & vbcr &_
"1 - Date from Today by Number of Days " & vbcr &_
"2 - Number of Days to Future Date " & vbcr &_
"3 - Number of Days between 2 Dates" & vbcr & vbcr &_
"Enter the number of your choice."

'  InputBox results
Question = InputBox(message,Notice)
'  Check for Null or empty inputbox then cancels
IF IsEmpty(Question) THEN
WScript.quit()

ELSEIF Len(Question) = 0 THEN
WScript.quit()

ELSEIF Question = 0 THEN
WScript.quit()

ELSE
  SELECT Case Question
   Case 1 Run(1)
   Case 2 Run(2)
   Case 3 Run(3)
  END SELECT

END IF

'  Case Statements for result from Inputbox
Sub Run(var)
Set WS = CreateObject("WScript.shell")
    Select Case var
Case 1 Message=inputbox("How many days do you want to count? " &  vbCrLf &  vbCrLf & "Either positive or negative number.", "  Enter the # of Days ")
    Message2=weekdayname(weekday(DateAdd("d", message, Date))) & ", " & DateAdd("d", Message, Date)
    Message = Message & " days from today will be " &  vbCrLf & "    " &  Message2
     
Case 2 Message1=inputbox("How many days until ?" &  vbCrLf &  vbCrLf & "Enter the Date as m/d/yy or mm/dd/yyyy", "  Enter Future Date ")
    Message2=DateDiff("d", Date , Message1)
    Message="There are " & Message2 & " days until " &  vbCrLf & "      " & Message1
     
Case 3 Message1=inputbox("Start Date ? " &  vbCrLf &  vbCrLf & "Enter the Date as m/d/yy or mm/dd/yyyy", "  Date From")
    Message=inputbox("End Date ?  " &  vbCrLf &  vbCrLf & "Enter the Date as m/d/yy or mm/dd/yyyy", "  Date To")
    Message2=DateDiff("d", Message1 , Message)
    Message="There are " & Message2 & " Days " &  vbCrLf & " From " & Message1 & vbCrLf & " To " & Message

    END SELECT
End Sub

'  Error handling message
IF Err.Number <> 0 THEN
msgbox "You entered something incorrectly.  Try again.  ",0+16," Ooopps...."
WScript.quit()
END IF

'  Final results
Msgbox Message, vbInformation, Notice

Step 7: Save the File

1)  Click File,
2)  Click Save,
3)  Choose the location where to Save this file,
4)  Change Save as type: from Text Documents (*.txt) to "All Files",
5)  Give the file a name i.e. DateCounter.vbs,
6)  Click Save.

Congratulations you are done.

Step 8: Observations & Summary

Warning:  If you make the wrong change to the aforementioned code.  You could, at worst, ruin your day.  It is no fun chasing errors.  What I have learned is that it is usually a simple mistake.
Disclaimer:  Modify at your own risk.

Observations
1)  It is easy to use.
2)  It is a small file and it sits on my desktop.
3)  It can be easily modified to do a lot of actions.
4)  You can enter a negative ( - ) number as well as the results displaying as a negative ( - ) amount.  You can count and display a past date.  i.e. Today is 4/20/2013.  How many days ago was Income Taxes file date 4/15/2013.  The response would be, "There are -5 days until 4/15/2013".
5)  This is a .vbs (Visual Basic Scripting) file you will need to be running Windows Operating System.
6)  If it does not work.  Then recopy the aforementioned code and paste it into the Notepad application then save the file with the extension .vbs.

Summary
This is a handy little app.  I wanted to keep adding functionality, but I will let you customize it, use your creativeness.  I am satisfied with the results. 

Hear advice, and receive instruction, so that you may be wise in your latter end.


<p><strong>Amazing!</strong></p><p>I kind of under-estimated the awesomness and usefulness of such a ingenious invention until I reached this part:</p><blockquote>Lets look at some practical applications for a <strong>Date Calculator App.vbs</strong>:<br> What is the mature date of Fantastic tomatoes if they say 72 days? - I can not wait to eat a Fantastic tomato.<br> How many days until Flag Day? - Flag Day is an under recognized observance.<br> How many days from next pay day to vacation? - How many days do I have to save money for vacation</blockquote><p>On a side note, what is a <strong>Fantastic Potato</strong>?:</p><blockquote>What is the mature date of Fantastic tomatoes if they say 72 days? - I can not wait to eat a Fantastic tomato.</blockquote><p>And on a second note, what's <strong>Flag Day</strong>?:</p><blockquote>How many days until Flag Day? - Flag Day is an under recognized observance.</blockquote>
<p>Thank you for reviewing and commenting. You are right VBS usage is understated, most people only use it for pranking, but it can be used for more dynamic applications as you can see in my more recent VBS instructables. <br><br>The examples given were for those who could not think of a use for this tool. The Fantastic tomato, it is a just a tomato I chose because of it&rsquo;s name and to show when the maturity would be by adding 72 days to a date.<br><br>Flag Day is a worldwide observance; whatever country you call home and whatever day is Flag Day be proud and fly that flag. Honor the people who died to give you freedom and stand for its values.</p>
<p>Thanks!</p>

About This Instructable

3,262views

8favorites

License:

Bio: I like to tinker, That is what I like to do. Sometimes I drop a rhyme, Along with a tool or two. I use what ... More »
More by ezman:Mini Brake Bender Sensory Rug Glue Gloves 
Add instructable to: