Search This Blog

2010/01/17

1)Create a vb 6.0 standard exe project add a textbox,a lavel ,add,calculate,reset
command button
2)copy assembly of NewMegacalc2 and NewMeanCalculator in current directory
3) copy type libraries for both of these.

Dim mobjCalc As NewMeanCalculator.MeanCalc
Dim mobjmega As NewMegaCalc2.IMegaCalc

Private Sub CmdAdd_Click()
mobjmega.Addinput (Text1.Text)
End Sub

Private Sub CmdCalculate_Click()
mobjmega.doCalculation
Text1.Text = mobjmega.GetOutput()
End Sub

Private Sub CmdReset_Click()
mobjmega.Reset
End Sub

Private Sub Form_Load()
mobjCalc = New NewMeanCalculator.MeanCalc
mobjmega = mobjCalc
End Sub

********************
Importing Vb.net assembly in vb 6.0:
Pre-requisite:

1)Create Class Library in VB.net add reference to NewMegaCalc2 a .Net Assembly
2)Add Following code

Public Class MeanCalc
Implements NewMegaCalc2.IMegaCalc

Dim mintValue As Integer
Dim mdblValues() As Double
Dim mdblMean As Double

Public Sub AddInput(ByVal InputValue As Double) Implements NewMegaCalc2.IMegaCalc.Addinput
mintValue = mintValue + 1
ReDim Preserve mdblValues(mintValue)
mdblValues(mintValue - 1) = InputValue
End Sub
Public Sub DoCalculation() Implements NewMegaCalc2.IMegaCalc.doCalculation
Dim IValue As Integer
mdblMean = 0
If (mintValue = 0) Then Exit Sub
For IValue = 0 To mintValue - 1 Step 1
mdblMean = mdblMean + mdblValues(IValue)

Next
mdblMean = mdblMean / IValue

End Sub

Public Function GetOutput() As Double Implements NewMegaCalc2.IMegaCalc.GetOutput
GetOutput = mdblMean
End Function

Public Sub Reset() Implements NewMegaCalc2.IMegaCalc.Reset
mintValue = 0
End Sub

Public Sub New()
Reset()
End Sub
End Class

******************************
PreRequesite:
1)create a vb.net class library called NewMeanCalc2 add following code to it
2)build project

Public Class Class1


End Class
Public Interface IMegaCalc
Sub Addinput(ByVal InputValue As Double)
Sub doCalculation()
Function GetOutput() As Double
Sub Reset()
End Interface

No comments:

Post a Comment