method in class

  • Thread starter Thread starter portroe
  • Start date Start date
P

portroe

If I have a method within a class,

how do I refer to that method from an even procedure?

thanks

Portroe
 
portroe,
By having a reference to an object of that class in the other procedure!
Either by creating the object in that procedure, or more then likely,
passing the object as a parameter.

Public Class Form1
Inherits System.Windows.Forms.Form

' other stuff omitted

Private Sub Command1_Click(...)

Dim joe As New Employee
MessageBox.Show(joe.ToString())

DisplayMessage(joe)

End Sub

End Class

Public Module MessageModule

Public Sub DisplayMessage(ByVal anEmployee As Employee)
MessageBox.Show(anEmployee.ToString())
End Sub

End Module

Remember that objects created from Classes are reference types, so passing
the object ByVal passes a copy of the reference to the object, there is only
a single actual object on the heap.

Hope this helps
Jay
 
portroe said:
If I have a method within a class,

how do I refer to that method from an even procedure?

From where? Inside the same object, simply call the procedure. Outside, you
need a reference to the object and call the method (well, inside too, but we
don't see it).
 
Back
Top