method in class

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

portroe

I need to slip a simple method into the following class,

the method should display a message box, displaying the entered
information..

Public Class employee
'Declaration of variables
Private iName, iTitle As String
Private iAge, iYearsofService As Integer


Property Name() As String
'The Property value is retrieved
Get
Return iName
End Get
Set(ByVal Value As String)
iName = Value
End Set
End Property

Property Title() As String
Get
Return iTitle
End Get
Set(ByVal Value As String)
iTitle = Value
End Set
End Property

Property Age() As Integer
Get
Return iAge
End Get
Set(ByVal Value As Integer)
iAge = Value
End Set
End Property

Property Yearsofservice() As Integer
Get
Return iYearsofservice
End Get
Set(ByVal Value As Integer)
iYearsofservice = Value
End Set
End Property

' Constructor
Public Sub New(ByVal Name As String, ByVal Title As String, _
ByVal Age As Integer, ByVal Yearsofservice As Integer)
Me.iName = Name
Me.iTitle = Title
Me.iAge = Age
Me.iYearsofservice = Yearsofservice
End Sub
End Class

######################

i can't figure the syntax,

thanks

Portroe
 
First I would suggest that you not include a MessageBox call in the method
code, rather create a method or a property that returns a string that is
formatted the way that you would like it displayed. Doing it that way you
can consume the class in a non-windows application, like ASP.NET, a Windows
service, etc.

In any case, you'll want to make sure that you have a reference set to
System.Windows.Forms.dll and then you can do something like:

Imports System.Windows.Forms

Public Class employee
'Declaration of variables
Private iName, iTitle As String
Private iAge, iYearsofService As Integer

Public Sub ShowInfo()
MessageBox.Show(iName & vbNewLine & iTitle & iAge.ToString() &
iYearsofService.ToString())

End Sub
Property Name() As String
....

End Class

Brian M. Reisman
MCAD, MCDBA, MCSD,
MCSE, MCT, OCA, NET+
My book on amazon: http://www.amazon.com/exec/obidos/tg/detail/-/0782141617
 
I really dont think u are serious but . .

Public sub displayPerson( msg as String )

MessageBox.Show( msg ) ' Msg composed of whatever you want and maybe &
other private variables

End Sub


Regards - OHM


Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
Very good . . .

Regards - OHM

MCAD, MCDBA, MCSD, MVP, MORe, MVBA,MNPA
MCSE, MCT, OCA, NET+, NWA, BWO, OBE, MRDO,MBizTA

========================================



Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
Portroe,
As Brian suggested, I would recommend creating a method that returns a
string that is formatted.

..NET has defined a consistent name for this method, that name being the
overridable method ToString that is inherited from System.Object.

A variation of Brian's sample that overrides Object.ToString would be:

Public Class employee
'Declaration of variables
Private iName, iTitle As String
Private iAge, iYearsofService As Integer

Public Sub ShowInfo()
MessageBox.Show(me.ToString())
End Sub

Public Overrides Function ToString() As String
Return iName & vbNewLine & iTitle & _
iAge.ToString() & iYearsofService.ToString()
End Function

End Class

This allows an Employee object to be used with various other classes in the
framework that will call Object.ToString to get a displayable representation
of the object. (for example adding an Employee object itself to a ListBox,
the ListBox will call ToString to get the value to display in the ListBox.

Hope this helps
Jay
 
Back
Top