1) comobjfile.vb
This contain the code for the component, and the logic for finding the
power of a number
2)WindowsApplication.vb
This class calls the component by first adding its reference and then
creating an object for the class and calling its function(namely the
function for calculating the power of a number)
***************************************************
Code begins here
***************************************************
//comobjfile.vb
Public Class Com_PowerFinder
Dim i, prod As Integer
Public Function findPower(ByVal num As Integer, ByVal power As
Integer) As Integer
prod = 1
For i = 1 To power
prod = num * prod
Next
Return prod
End Function
End Class
=====================================
//WindowsApplication.vb
Public Class Form1
Dim base, power, answer As Integer
Private Sub cmdFindPower_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmdFindPower.Click
If txtboxNum.Text = "" Then
MsgBox("Please enter a number")
ElseIf txtboxPow.Text = "" Then
MsgBox("Please enter a power for the number")
Else
'Code begins for calling and intializing the component
base = Val(txtboxNum.Text)
power = Val(txtboxPow.Text)
Dim comObj As New ComObjFile.Com_PowerFinder()
answer = comObj.findPower(base, power)
txtboxAns.Text = answer
End If
End Sub
End Class
========================================
Finally the gui is as follows
Enter the number : ____________
Enter the power of number : ________
=========
||find power ||
=========
Power of number is : _________
Note: validation as to whether number or power if left blank is
checked
Know bugs
----------------
If you leave both the number and power field blank, its shows only
number field is left blank