Metin Erman

Metin Erman

  • NA
  • 9
  • 0

Translating a Direct Event call in C# to VB.net...need a little help

Jun 17 2010 11:51 PM
OK, I have a situation where I am trying to use some code from C# and translate it to vb.net.  I am stuck at a point where the C# code calls an Event directly.  I know normally you would use the addhandler and raiseevent methods to do the same thing, but the way it is set up is slightly confusing to me.  I am pretty sure once someone shows me the correct method, I will slap my head and say "Doh!", but I am tired of banging my head into the wall on this one.  OK, here is the code in c# with the vb.net translation under it:

c#: public event EventHandler<SpriteCollisionEventArgs> SpriteCollision
vb:  Public Event SpriteCollision As EventHandler(Of SpriteCollisionEventArgs)

                          c#:  //Handle collision detection with itself
                            if (se.DetectCollisionSelf && SpriteCollision != null)
                                se.PerformSelfCollisionDetection();

                          vb:  'Handle collision detection with itself
                           If se.DetectCollisionSelf AndAlso SpriteCollision IsNot Nothing Then
                                se.PerformSelfCollisionDetection()
                           End If

The problem lies in the "if" statement on the event, which doesn't work in vb.net, saying "Public Event SpriteCollision is an event and cannot be called directly. Use a RaiseEvent statement to raise an event."

I am assuming I would call the raiseevent method and then run the if code in there, but then I am confused as to what I am running it on, since the event in c# is called directly with no arguments..

Any help would be appreciated...

Matt

Answers (3)