sas

Topic: Projects Using  Intrinsic and Professional ActiveX Controls


Objective of this Lesson:

     The objective of this lesson is to create the following projects illustrating the use of Intrinsic and Professional ActiveX Controls.

  • Creating Digital Clock using the Intrinsic Timer Control
  • Creating  Bar Chart using the Professional MS Barchart Control
  • Creating Project using Combo Box


What is ActiveX?

     ActiveX is a reusable and portable software component or control built according to what are called COM(Component Object Model) specifications.   It is the brainchild of Microsoft.   It is the practical realization of the philosophy, “write once use anywhere and everywhere”.    It provides a building block solution to complex problems.   We  have already seen that VB-6 comes with certain intrinsic ActiveX controls which offer some functionalities    Such controls can be used not only in VB, but also in other ActiveX compliant languages like VC++., VJ++, Delphi  etc.

Can you Create Your own ActiveX Controls?

     It is well known that any complex application is made of compatible combinations of some basic functionalities.  If you have predefined ActiveX controls to provide these basic functionalities, VB-6 offers language support to package the basic controls to another new single ActiveX control thereby providing an ActiveX solution to the complex problem.    In fact VB-6 has been developed essentially as a Control Creation Language.  Possibly you can visualize a scenario when every complex application will be solved by a single user created aggregate ActiveX control.

Visual Basic  ActiveX Controls:

     When you start VB, the first window called the design window shows some 20 intrinsic controls like label, command button, option button etc., in the Toolbox.   These controls cannot be removed from the Toolbox.   The Professional Edition of VB provides some  34 more ActiveX controls which can be brought into the Tool box before using them.    These controls can be added to or removed from the Toolbox.   In order to view all the VB ActiveX controls  select ‘New Project’ from the File Menu.   You will get the New Project Menu as shown in the figure 1.   Click on the ‘VB Pro Edition Control’.   The Toolbox of the Design Window will now show the icons of all the ActiveX controls as shown in the figure 2.   When you move the mouse pointer over the icon,  the names of the controls will appear below them.

project1

                                       Figure 1

project2
                                             Figure 2

Adding ActiveX Controls to the Toolbox:

     In order to add one or more ActiveX controls to the Toolbox,  select the item ‘Components’ from the Project menu.   The Components Dialog Box will appear on the screen as shown in the figure 3.   Select the required control by clicking on the rectangular box at the beginning.   After selecting the required controls, click OK.    The icons of the selected controls will now appear on the Tool box and you can use them just as you will use any other intrinsic ActiveX control.

project3
                                        Figure 3

Functions of Some important ActiveX Controls:

     We give below a list of some important ActiveX controls added in the Professional Edition of VB-6.   This is in addition to the intrinsic controls already introduced in earlier versions.  
  • 1. The Common Dialog Control  enables the users to create Dialog Boxes (open, save, print, setup, font, help and so on) in their own applications.
  • 2. The Animation Control  enables the users to play silent avi files producing animation appropriate to the operations performed.

 

  • 3. The Communication Control  describes how to use it with a modem to dial a phone number, interact with another modem or add advanced communication functionality to your applications.
  • 4.  The Internet Transfer Control enables the users to transfer files to and from a remote computer using TCP or FTP protocols.

 

  • 5.  The ListView  Control enables the users to organize and view the data in deifferent ways using the View Property.
  • 6.  The MAPI Control  enables the users to sign-on to an electronic messaging system, access an Inbox, send or receive messages or send file attachments.

 

  • 7.  The Masked -Edit Control  enables the users to create mask platforms that prompt them for date, time currency or customized data input.
  • 8.  The MSChart Control enables users to create barchrts, assign and edit backdrops and load data from an array.

 

  • 9.  The Multimedia Control enables the users to control and manage t5he recording playback of a variety of multimedia using a simple push-button interface.
  • 10.  The PictureClip Control enables the users to create an image resource for other Visual Basic Controls by storing multiple images in a single image resource and then retrie3ving individual images by ‘clipping’ specific regions.

 

  • 11. The ProgressBar Control enables the users to get a feedback about a lengthy operation by pictorially displaying a moving coloured bar.
  • 12.  The RichTextBox Control  enables the users to get word-processing features in a TextBox.

 

  • 13. The Slider Control  enables the users to select a range of data between a maximum and a minimum setting.
  • 14.  The StatusBar Control  enables the users to display text and images in the Status Bar.

 

  • 15.  The Sysinfo Control  enables the users to determine the current operating system, how to monitor and respond to Plug and Play events or changes in AC and battery power status.
  • 16.  The Tabbed Dialog Control enables the users to present several dialogs or screens of information on a single form using the same interface.

 

  • 17.  The ToolBar Control  enables the users to reconfigure the Toolbar by setting the AllowCustomize property.
  • 18.  The TabStrip Control enables the users to create tabs by adding tab objects to the tab collection.  Use an imagelist controlo to supply bitmaps for the tabs. 

 

  • 19  The TreeView Control enables the users to expland the node objects and explain how they relate to each other.
  • 20.  The WinSock Control enables the users to send data to remote computers using TCP or UDP protocols.

 

  • 21.  The ADO or ActiveX Data Model is another database object model  like the DAO model which is useful in certain cases

 
 Developing Projects using these Activex Controls will form the subject matter for  a few more lessons to follow.

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.

project4

                         Figure 4

Entering the Event Codes:

     Open the code window by double clicking the Timer control  and enter the code as shown in the figure 4a.  

Private Sub Timer1_Timer()
If Label1.Caption <> CStr(Time) Then
Label1.Caption = Date
Label2.Caption = Time
End If
End Sub

Figure 4a.

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.

project5
                            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.   The bar chart will appear as shown in the figure 7.

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

project6

                                          Figure 6

project7

                          Figure 7

3. Project using Combo Box:

     In this project we use 3 combo boxes to set different values for principal, ratepercent and years and compute simple and compound interest for the different sets of values.   Drag  7 command buttons, 7 labels, 2 text boxes and 3 combo boxes in the form, size them caption them and position them as shown in the figure 8.   The different sets of values for principal, ratepercent and years can be added either at design time or during run time.   If you want to add items during design time, set the list property. Check list in the property box, then add items, pressing ctrl + enter after each item.    To enter items at run time you have to write codes.   Items that are selected in the combo boxes can be deleted by the delete buttons..  Open the code window and enter the codes as shown in the figure 8a.   Save and run the project and experiment with the different controls.   A typical run mode window is shown in the figure 9.
 

project8

Private Sub Command1_Click()
Text1.Text = Combo1.Text * Combo2.Text * Combo3.Text / 100
Text2.Text = Combo1.Text * (1 + Combo3.Text / 100) ^ Combo2.Text - Combo1.Text
End Sub

Private Sub Command2_Click()
principal = InputBox("enter principal to be added")Combo1.AddItem principal
End Sub

Private Sub Command3_Click()
Combo1.RemoveItem Combo1.ListIndex
End Sub

Private Sub Command4_Click()
ratepercent = InputBox("enter ratepercent to be added")
Combo3.AddItem ratepercent
End Sub

Private Sub Command5_Click()
years = InputBox("enter years item to be added")
Combo2.AddItem years
End Sub

Private Sub Command6_Click()
Combo2.RemoveItem Combo2.ListIndex
End Sub

Private Sub Command7_Click()
Combo3.RemoveItem Combo3.ListIndex
End Sub

Private Sub Command8_Click()
Text1.Text = principal * ratepercent * years / 100
End Sub
Private Sub Form_Load()
Combo1.AddItem 500
Combo1.AddItem 600
Combo1.AddItem 700
Combo2.AddItem 2.5
Combo2.AddItem 3.5
Combo3.AddItem 7.5
Combo3.AddItem 12.5
End Sub

 Figure 8a

project9

Summary:

     In this lesson we have described some three  projects and learnt a few things about ActiveX controls and their uses.   In the next lesson we will consider some more ActiveX Controls.

                                                                                                                                                                      
Prev
                                                                                                              

 

 

 

 

 

 

 

 




footer back link


 

Error in my_thread_global_end(): 1 threads didn't exit