Saturday, October 20, 2012

Use of DATE$

One of the requirements for your output in this class is to include the date after your name in the output window. The question is, which date? Do you want the date you wrote the code, the due date for the project, or another date?

If you wanted to display the date you wrote the code (or the due date), you could do it like so

PRINT "10-18-2012"

putting the static date between a pair of quotation marks so that it becomes a string literal. Often, however, what you really want to display is the date that the user is running the code, the current date. The computer knows the current date but how do you, as the programmer, access it so that you can display it to the user? As it turns out, this is really easy to do in QBASIC.

Instead of using a string literal with the static date, you use this

PRINT DATE$

The program acquires the current date from the system and displays it in your program. Here is a bit of source code which uses WHILE...WEND to triple the user's input value and also uses DATE$ to print the current date.

Here is a run of the code. Since I ran this code on Thursday morning, the date on my screenshot is October 18th.

This is a run of the same code today. See how the date has changed?