 |
| VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 6th, 2005, 08:06 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Inherits sub class
Hi all,
Ok, i am developing a baseclassemployee and a sub class(Boss) which will inherit from the base class. this is what I have so far...
Public Class myBaseEmployee
Private strFirstName As String
Private strLastName As String
Private intMonthlyPay As Integer
Public Sub New(ByVal FirstName As String, ByVal LastName As
String)
strFirstName = FirstName
strLastName = LastName
End Sub
Public Property FirstName() As String
Get
Return strFirstName
End Get
Set(ByVal Value As String)
FirstName = Value
End Set
End Property
Public Property LastName() As String
Get
Return strLastName
End Get
Set(ByVal Value As String)
LastName = Value
End Set
End Property
Public Overrides Function Tostring() As String
Return strFirstName & " " & strLastName
End Function
Public ReadOnly Property MonthlyPay() As Integer
Get
Return intMonthlyPay
End Get
End Property
Now I have to create a boss class which inherits from the base class and requires the following fields--Constructor--Takes first name and last name as annual salary arguments Properties--first name,last name,annual salary,monthly pay(Annual salary/12) Method--ToString (this overrides the base class method and returns the type of employee and full name of the employee in the form "Boss: John Does"
There are another 3 classes but I think I will be able to work those out by myself if I can get this first one sorted
Any help would be much appreciated...
B
|
|

June 6th, 2005, 03:09 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Code:
Public Class Boss
Inherits myBaseEmployee
Private _firstName, _lastName As String
Private _annualSalary As Decimal
Public Sub New(ByVal firstName As String, ByVal lastName As String, ByVal annualSalary As Decimal)
Me._firstName = firstName
Me._lastName = lastName
Me._annualSalary = annualSalary
End Sub
Private ReadOnly Property monthlySalary() As Decimal
Get
Return _annualSalary / 12
End Get
End Property
Public Overrides Function toString() As String
Return "Boss: " & Me._firstName & " " & Me._lastName
End Function
End Class
|
|

June 7th, 2005, 02:42 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you jaucourt, you are a star !!
|
|

June 7th, 2005, 04:20 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi jaucourt,
I have a "display" button on my form, could you help me with the code for displaying the boss class in a message box once the display button has been clicked?
Thanks so much for your help, you are a lifesaver....
B
|
|

June 10th, 2005, 05:16 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Presuming the button is called button1, you can double click it to create the handler:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
objBoss = New Boss("Bob", "Geldof", 100000)
Messagebox.Show(objBoss.toString())
End Sub
Quote:
quote:Originally posted by Brettvan1
Hi jaucourt,
I have a "display" button on my form, could you help me with the code for displaying the boss class in a message box once the display button has been clicked?
Thanks so much for your help, you are a lifesaver....
B
|
|
|
 |