VISUAL BASIC_6
 

10. Project using ActiveX DLL


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.

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.

 

                   Figure 4

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.   

                       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

Figure 6


 

Copyright © 2001 Selfonline-Education. All rights reserved.