Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delegates C# to VB 1

Status
Not open for further replies.

cappmgr

Programmer
Joined
Jan 29, 2003
Messages
639
Location
US
I am trying to convert C# code into VB code and getting confused with delegates. Delegates are objects that can call methods of other objects.
The lines with the += are the lines I cannot figure out how to convert.
What I have tried are different combinations of AddressOf and AddHandler.
Each time a blue line with a mouse over stating it is not an Event or the delegates are not of the same type. To compound the issue I do not know enough about delegates and events.

Private _preClean As TestCleanup

Delegate Sub TestCleanup()

Private _preTestCleanup As TestRunner.TestCleanup

Public ReadOnly Property PreTestCleanup() As TestRunner.TestCleanup
Get
Return _preTestCleanup
End Get
End Property
...
End Structure

Public Sub AddTestGroup(ByVal tg As TestGroup)
_preClean += tg.PreTestCleanup
_testCaseDel += tg.TestRun
_postClean += tg.PostTestCleanup
_testValidity += tg.TestValidityCheck
End Sub 'AddTestGroup

Any help appreciated,
Marty
 
Maybe this will help....

Public Class Class1
Delegate Sub TestCleanup()
Private _preClean As TestCleanup

Public Sub AddTestGroup(ByVal tg As TestGroup)
If _preClean Is Nothing Then
_preClean = New TestCleanup(AddressOf tg.PreTestCleanup)
Else
_preClean.Combine(_preClean, New TestCleanup(AddressOf tg.PreTestCleanup))
End If
End Sub
End Class

Public Class TestGroup

Public Sub PreTestCleanup()

End Sub
End Class
 
stsuing,
It did help. The only thing I did differently is reassign back to _preClean.

_preClean = _preClean.Combine(_preClean, New TestCleanup(AddressOf tg.PreTestCleanup))

Thank you very much,
Marty
 
It is good and I have used it but VB does not overload operators like C# and it chokes on the overloaded operators.
Marty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top