0

I have 2 project in my Solution.
Lets say Proj A and Proj B.

Proj A is having my custom event. and same Proj is Raising that event using RaiseEvent Function of Vb.net And Proj B is having reference of Proj A.
Proj B is adding handler for Proj A's custom event.

but my custom event cant raise. Could any one can explain me how can I do that.?

Edit:

Proj A

Public Shared Event cardReadComplete(ByVal data As String)
 Public Sub kbHook_KeyDown(ByVal Key As Windows.Forms.Keys) 
  IO.File.AppendAllText("E:\log.log", Key.ToString() & vbCrLf)
 RaiseEvent cardReadComplete(encryptedData)
End Sub

Proj B

 Private Sub handleSwipeCardRequest(ByVal msgText As String)
        AddHandler CardReader.Main.cardReadComplete, AddressOf sendSwipeCardDetails
        CardReader.Main.cardReadComplete()
End Sub

I am calling handleSwipeCardRequest function first and then Raising its event.

Edwin de Koning
  • 14,209
  • 7
  • 56
  • 74
Jaynesh Shah
  • 158
  • 1
  • 1
  • 14
  • 2
    Have you declared the variable that holds the instance of whichever type it is in Proj A using the WithEvents keyword? Please post some sample code. – Simon Oct 18 '11 at 10:08
  • 1
    You seem to mixing up the Sub and the Event name. And it looks like you'll have to press a key to trigger the event. Although it is a KeyDown event without the Handles keyword so it probably never fires. – Hans Passant Oct 18 '11 at 12:34

2 Answers2

0

Another way :

AddHandler kbHook.KeyDown , AddressOf Me.kbHook_KeyDown
Thomas
  • 24,234
  • 6
  • 81
  • 125
0

Your event will be raised when kbHook_KeyDown gets called, assuming it gets called after the AddHandler line is executed. Are you sure that the KeyDown function gets called? As Hans Passant said, you might be missing a Handles keyword:

Public Sub kbHook_KeyDown(ByVal Key As Windows.Forms.Keys) Handles kbHook.KeyDown
    ...
End Sub
Meta-Knight
  • 17,626
  • 1
  • 48
  • 58