Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
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
 
Old March 21st, 2005, 02:50 PM
Authorized User
 
Join Date: Oct 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question about Inheritance in classes

I have a question about inherited classes. I have a class Days which has properties of days worked. I also have a class Hours which has properties of hours worked. (This might become more clear in the below code).

What I want is to create a Class called "ExemptEmployee", which inherits the Days class, and then set the properties contained in Days from within a method in the ExemptEmployee class. But when I type the "Me" keyword it doesn't work out. Can someone tell me if I'm on the right track with this? TIA!

================================================== =
Public Class ExemptEmployee
        Inherits Days

        Public Shared Sub FetchExemptEmployeeDays()
            'sql fetch which gets the employee days from the Days table in
            'the Timesheet database

            Dim strSQL as String = "SELECT Regular_Days, Vacation_Days, Sick_Days, " & _
                                "Jury_Days, Funeral_Days, Holiday_Days, Unpaid_Days FROM " & _
                                "Days WHERE SSN = '" & s_SSN & "' AND Pay_Period_Number = " & s_PayPeriodNumber

            Dim oConn as New SqlConnection(DSN.FetchDSN(DSN.DataBaseName.Timesh eet))
            Dim oCmd as New SqlCommand
            Dim oReader as SqlDataReader

            With oCmd
                .Connection.Open()
                .CommandText=strSQL
                .CommandType=CommandType.Text
                .Connection=oConn
                oReader = oCmd.ExecuteReader
                While oReader.Read
                    'IN THIS LOOP I WANT TO SET PROPERTIES WHICH WOULD BE INHERITED FROM THE DAYS CLASS.
                End While
            End With

        End Sub

    End Class


================================================== ===========
Public Class Days
            'regular days
            Private dRegularDays as Integer
            'vacation days
            Private dVacationDays as Integer
            'sick days
            Private dSickDays as Integer
            'holiday days
            Private dHolidayDays as Integer
            'jury
            Private dJuryDays as Integer
            'funeral
            Private dFuneralDays as Integer
            'Duty days
            Private dDutyDays as Integer
            'Duty weekends
            Private dDutyWeekends as Integer

        #Region " Property declarations "
                Public Property RegularDays as Integer
                    Get
                        RegularDays = dRegularDays
                    End Get
                    Set
                        dRegularDays = Value
                    End Set
                End Property

                Public Property VacationDays as Integer
                    Get
                        VacationDays = dVacationDays
                    End Get
                    Set
                        dVacationDays = Value
                    End Set
                End Property

                Public Property SickDays as Integer
                    Get
                        SickDays = dSickDays
                    End Get
                    Set
                        dSickDays = Value
                    End Set
                End Property

                Public Property HolidayDays as Double
                    Get
                        HolidayDays = dHolidayDays
                    End Get
                    Set
                        dHolidayDays = Value
                    End Set
                End Property

                Public Property JuryDays as Double
                    Get
                        JuryDays = dJuryDays
                    End Get
                    Set
                        dJuryDays = Value
                    End Set
                End Property

                Public Property FuneralDays as Double
                    Get
                        FuneralDays = dFuneralDays
                    End Get
                    Set
                        dFuneralDays = Value
                    End Set
                End Property

                Public Property DutyDays as Integer
                    Get
                        DutyDays = dDutyDays
                    End Get
                    Set
                        dDutyDays = Value
                    End Set
                End Property

                Public Property DutyWeekends as Integer
                    Get
                        DutyWeekends = dDutyWeekends
                    End Get
                    Set
                        dDutyWeekends = Value
                    End Set
                End Property
        #End Region


        End Class




"A spirit with a vision is a dream with a mission"
__________________
\"A spirit with a vision is a dream with a mission\"
 
Old March 21st, 2005, 06:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're using a Shared method to fetch the employee.

A Shared method works on the class, and not on the instance of the class. So, with a Shared method, there is no Me to refer to a current instance because there *is* no current instance.

Either drop the Shared keyword and instantiate an ExemptEmployee instance in your calling code before you call FetchExemptEmployeeDays on that object.

Alternatively, instantiate a new instance of ExemptEmployee inside the FetchExemptEmployeeDays method and return that:

Public Shared Function FetchExemptEmployeeDays()

Dim myExemptEmployee As New ExemptEmployee
  ' Go to database
  ' Set properties
  myExemptEmployee.SomeProperty = SomeValueFromDatabase
  Return myExemptEmployee
End Function

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible via Inheritance!!! mike_remember ASP.NET 2.0 Professional 0 November 26th, 2007 10:25 AM
Inheritance michaelcode ASP.NET 2.0 Basics 5 September 26th, 2006 01:40 PM
Need help with inheritance filip BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 August 25th, 2006 09:38 PM
Question about Class Inheritance forkhead Pro VB.NET 2002/2003 0 March 21st, 2005 03:37 PM
Newbie question on the 2nd ed: Class inheritance elde BOOK: Professional C#, 2nd and 3rd Editions 0 December 9th, 2004 03:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.