Snyder 20 October ’99
Project 1, Part I
Astrological Toys
In this project a series of window applications will be written that look up and display astrological signs and dates. The applications that will make up the project are as follows:
- This Time – a digital clock with the date on the window bar
- Sign Finder – present your birthday and be told your astrological sign
- Zodiac Range -- give your sign and receive the interval containing your birthday
- Day Finder – generalizing the Sign Finder to ask a series of questions to find the respondent's birthday using binary search
The projects are written in Visual Basic 6.0 and serve as the initial foray into algorithmic thinking, program design and the characteristics of VB6.
It is suggested you create a new folder for each project. This will assist you in keeping track of all of the various files produced as well as simplifying saving your work to the floppy disk.
This Time. This is a simple digital clock program with the date on the window bar. The goal in writing the digital clock program is to create an initial VB6 program. The essential features are
- Change the form name.
- Change the caption on the window bar.
- Place and use a label control.
- Place and use a timer control.
- Customize the window to be attractive.
- Save the project and form files.
Each of these features will be discussed below. The ThisTime application has the following window interface:
Open Visual Basic 6.0 (accessed as an element of Visual Studio 6.0), and click on the
Standard.exe
application that is highlighted. This will open a project, probably called
Project 1, with a new form, called Form1.
- Form Name Change.
Revise the name of the form to
frmClock by editing the (Name) entry in the form’s property list.
Change Caption. The caption on the form’s window bar is to be assigned the current date at the time the window is loaded. Therefore, the "Form_Load" event should be customized to assign the date to the caption. The following code should suffice:
Private Sub Form_Load()
frmClock.Caption = Date
End Sub
Date
is a built-in global variant object that returns the date as set on the computer in the form mm/dd/yy. When the form is loaded, the current date will appear on the window bar.
Place Label. A label control is placed on the form, and the name of the label revised to be lblTime. Select a better font, and enlarge it to approximately 20 points.
Place Timer. A timer control is placed on the form (it can be hidden), and the name of this control should be revised to be tmrTime. Set the interval property to be 1000, i.e. the timer should "go off" every 1000 milliseconds = 1 second. That time event should cause the caption on the label to be set to the time. Code along the following lines should suffice:
Private Sub tmrTime_Timer()
lblTime.Caption = Time
End Sub
Time
is like Date, a built-in global variant that returns time in hh:mm:ss xM format. What happens is this: The timer "goes off" every second. That event causes the procedure "tmrTime" to be called. It changes the caption of the label to the current time. Whenever anything on the form is changed, the window is "repainted," i.e. redisplayed. Since most of the information is unchanged and remains in a fixed position, the clock appears to be ticking.
Customize. Change the properties of the window to be attractive. This includes …
- Change the form’s background color.
- Shrink the window so that it nicely frames the time symbols.
- Revise the background color of the label to match the background of the window.
- Revise the color of the font of the label to be attractive and to contrast pleasantly with the window’s background.
- Set the starting position property of the form to be the center of the screen.
- Save
. Save the project as
ThisTime. This will create a file called ThisTime.vbp with a multicolored project icon to go with it, and ThisTime.vbw with the standard window icon. You should also save the form, which will produce the file, frmClock.frm with the form icon and frmClock.frx, which has the standard windows icon. There may also be a file with a .scc extension in the same directory, which you can ignore.
When completed, compile your program by going to
Make ThisTime.exe in the File menu. That operation will make another file in the directory you. This is the ThisTime.exe file. To run your program, double click on the ThisTime.exe.
To save your work you will have to move these files to your floppy disk or to your Dante directory. And to work on them again, you’ll have to bring them back from Dante to a PC.