Creating COM Using VB | Component Object Model in Visual BASIC

To create a Component for calculating the employee salary by using VB. Create component Object Model
STEP BY STEP ALGORITHM:
Part-1: ActiveX Control
Building a Simple ActiveX Control in VB
This set of instructions will show you how to build, test and package a trivial ActiveX control. The control is used to calculate the Employee Salary details. The steps are as follows,
1. Open VB 6.0
2. From that select Active-x control then click open.
3. Select add-ins from the main menu select add-in manager. A dialog window will be displayed.
4. Select active-x control interface wizard as loaded and select load as startup. Then click ok
5. Again select add-ins from the main menu. Select active-x control interface wizard. One dialog window will be displayed. In that dialog window click next button.
6. Add a property as salary and also add methods as PF, URA, MR & NET.
7. Click the next button select the data type as double for both property and methods. And finally click the finish button
8. Double click the coding part and type the coding
9. Select the project and run
10. Select file menu select make the project as .ocx save the project and the user control.
Create component Object Model in Visual Basic

Part-2:
Testing your OCX from a new VB project
1. Open VB 6.0
2. Select standard.exe and design the window as shown in the output figure.
3. Select project from the Main menu. From that select components -> select your user control (project name) and then click ok.
4. Place the user control in your designed window.
5. Select the command button and write the proper coding.

Finally run and build your application | component Object Model in Visual Basic
Steps to create data report and data environment:
1. Click components. From that select designer. Then a dialog window displayed in that window select data report & data environment then click add Data Report & Data Environment.
2. Select Add-ins select visual data manager -> select file -> new->select Microsoft access version 7.0 then give a database name then right click the properties click new table give a table name then add the fields (name, salary, city). Finally select Build the table.
3. Select Data Environment. From that right click the connections. Click the properties one dialog window displayed. From that window select Microsoft Jet 3.51 OLE DB providers. Then click next.
4. In the connection tab select your database name, then click test connection a message box will be displayed as Test Connection succeed then click ok. Again In Data Environment, right click connection1 add a command. A new command is added. Now right click the command select properties.
5. In the property window type the SQL statement as select * from your6. Now your fields are added in your command. Then place the fields from Data Environment into Data Report. Then open the property window for Data Report, click data member as your command and then select data source as Data Environment.
7. Then select Data Environment properties. Give the data source and data member.
8. Then write the proper coding.
9. Finally run and build your application.

source code programming
CODING: component object model Source code programming
1. ActiveX Control
Public Property Get salary() As Double
salary = m_salary
End Property

Public Function PF() As Double
PF = m_salary * (8 / 100)
End Function

Public Function URA() As Double
URA = m_salary * (5 / 100)
End Function


Public Function MR() As Double
MR = m_salary * (4 / 100)
End Function

Public Function NET() As Double
NET = Val(m_salary) + Val(PF) + Val(URA) + Val(MR)
End Function

2. Standard Exe
Form 1
Private Sub Command1_Click()
UserControl11.salary = Text3.Text
Text4.Text = UserControl11.PF
Text5.Text = UserControl11.URA
Text6.Text = UserControl11.MR
Text7.Text = UserControl11.NET
End Sub

Private Sub Command2_Click()
Data1.Recordset.AddNew
Data1.Recordset.Fields(0) = Text1.Text
Data1.Recordset.Fields(1) = Text2.Text
Data1.Recordset.Fields(2) = Text3.Text
Data1.Recordset.Update
End Sub

Private Sub Command3_Click()
DataReport1.Show
End Sub

Software component Lap | source code programming

Related post