2. Projects Using Intrinsic and Professional ActiveX
Controls(1)
1. Project using the Timer Control:
A digital clock is a very simple but very useful application
involving the timer control. This
project requires a timer and two labels.
The running time will be displayed in one label and the current date
will be displayed in the other label.
Timer is an Iintrinsic ActiveX control and so is already present in the
Tool Box. Drag one timer and two label
controls into the form. Give the labels appropriate size, font and
border and set their caption property blank.
Set the timer interval property as 1000(one second) and the Enabled
property as True. The project at the
design time looks as in the figure 4.

Figure 4
Entering the Event Codes:
Open the code window by double clicking
the Timer control and enter the code.
Private
Sub Timer1_Timer()
If
Label1.Caption <> CStr(Time) Then
Label1.Caption
= Date
Label2.Caption
= Time
End
If
End
Sub
Running the Project:
Select Start from the Run Menu. The clock will begin to run. The current date will be displayed in the
other label. The run mode window is as shown in the figure 5. Another important point you notice is that
the timer control does not appear in the run mode, and is invisible, but works only from behind.

Figure 5
Building BarChart Project:
Bar Charts are very useful for displaying
business data, say product sales versus years. VB has an ActiveX control named Microsoft Chart Control, to
draw two dimensional and three
dimensional bar charts.
Controls used in this project:
The MS Chart control is brought into the
Toolbox from the component dialog box.
If it is not available in the dialog box, click the browse button and
select the same from the control files directory. The MSChart icon will appear in the tool box. It must be placed in a bitmap container. So
a picture box control is first drawn
into the form. Then the MSChart
control is placed inside the picture box.
Then a command button is placed in the form. It is given the caption and name as ‘setchart’. The design window will look as shown in the
figure 6. The code window is opened by
double clicking the setchart button and the code is entered as shown in the
figure 6a. Save the form as chartfrm
and the project as chartprj. Select
start from the Run menu. You will have
to enter 9 data values in response to prompts.
Private
Sub
setchart_Click()
Dim
i, j, k
MSChart1.RowCount
= 3
MSChart1.ColumnCount
= 3
MSChart1.chartType
= VtChChartType2dBar
k
= 1996
For
i = 1 To 3
For
j = 1 To 3
MSChart1.Row
= i
MSChart1.Column
= j
MSChart1.RowLabel
= k
MSChart1.Data
= InputBox("enter values for row " & i & " column "
& j)
Next
j
k
= k + 1
Next
i
End
Sub
Figure 6a

Figure 6

Figure 7
   |