sas

Topic: Project using ActiveX DLL


 What is DLL?
     A dynamic-link library(DLL) is a set of procedures that are external to your application, and can be called from your application.  DLLs are not bound to your executable file, and so they can be linked to your application at run time, instead of being loaded at compile time.   The libraries can be updated independently of the application and multiple applications can share a single DLL.

Advantages of using DLLs:

    DLLs can accomplish tasks that are difficult with VB.
    DLLS will run faster than VB code resulting in improved performance.
    DLLs can be updated independently of the application.

Declaring a DLL Procedure:

     DLL procedures reside in files that are external to your VB application and so you must declare a procedure before you call it.   Declaring a procedure provides VB with the information it needs to find and run the procedure you want to use.

Steps used in creating an ActiveX DLL Project:

  1. Open the VB IDE.
  2. Select New Project from the File Menu.   You will get the Project window as shown in the figure 1.   Select the icon named ActiveX DLL.  
  3. Add a form to the Project using the Add Form window shown in the figure 2.   This window is obtained by selecting Add Form from the Project Menu.. Change its name property as chartfrm.
  4.  Change the name property of the project as chartprj.
  5. Change the name property of the class modules as chartcls.
  6. Drag a MSChart control in the form and size it appropriately as shown in the figure 3.
  7. Save the modules as chartcls, the form as chartfrm and the project as chartprj.   These names must appear as shown in the figure 3.
  8. Now you have to write the DLL procedure for drawing a chart.   Double click the class module.   You will get the general declaration window..   Select Add procedure item from the Tools menu.   You will get the Procedure heading and the ending tags.   Write the body of the procedure.   The dll procedure is entered as in the figure 3a. 

d1

                       Figure 1

d2

               Figure 2

d3

                          Figure 3

Public Sub setchart(ByVal data1, ByVal noofrows, ByVal noofcols)
Dim i, j, k As Integer
k = 1995
chartfrm.MSChart1.RowCount = noofrows
chartfrm.MSChart1.ColumnCount = noofcols
chartfrm.MSChart1.chartType = VtChChartType2dBar
For i = 1 To noofrows
For j = 1 To noofcols
chartfrm.MSChart1.Row = 1
chartfrm.MSChart1.Column = j
chartfrm.MSChart1.RowLabel = k
chartfrm.MSChart1.Data = data1(i, j)
Next j
k = k + 1
Next i
chartfrm.Show
End Sub

     Figure 3a

Save the project.   Select ‘Make chartproj.dll’ from the file menu thereby saving the complete DLL procedure.file.   This DLL file must be referenced by selecting the DLL project from the reference library window.   Select references from the project window.   You will get the list of reference libraries in the alphabetical order as shown in the figure 4.   Select the file chartprj.

     In order to call the DLL procedure start the Standard Exe project.   Drag a command button in the Design window.   Change its caption and name as calldll and locate it as shown in the figure 5.   Open the code window for the command button and enter the code for calling the DLL as shown in the figure 5a.   Save the form and the project as dllform aand dllproj respectively.   Run the project.   You will have to enter the data for the number of rows, number of columns , values for the rows and columns.   Finally you will get the bar chart for the supplied data as shown in the figure 6.

Private Sub Command1_Click()
Dim r, c
Dim data22(1 To 10, 1 To 10)
r = Val(InputBox("enter the number of rows"))
c = Val(InputBox("enter the number of columns"))
For i = 1 To r
For j = 1 To c
data22(i, j) = Val(InputBox("enter value for row " & i & "column " & j))
Next j
Next i
Dim obj As chartprj.chartcls
Set obj = New chartcls
Call obj.setchart(data22, r, c)
End Sub

Figure 5a

d4

                  Figure 4

d5

                              Figure 5

d6

           Figure 6

Prev

 

 

 

 

 

 

 

 

 


footer back link


 

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