Wrox Programmer Forums
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 May 2nd, 2005, 05:19 AM
Authorized User
Join Date: Oct 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Classes

The simple example below works find. However if I change the 'Access Level' of the properties in the Box class to 'Protected Friend' which I figured would work as well, it errors with "Public member 'Height' on type 'Box' not found."

If I then change the definition of myBox and myCreate to:

Dim myBox As Box
Dim myCreate As Crate

myBox = new Box
myCreate = new Create

It works.

I cant see why changing the Access Level caused a problem and why I had to change the definition of my instances of the objects? Any comments please?

Module Module1

    Sub Main()
        Dim myBox = New Box
        Dim myCreate = New Crate

        'myBox = New Box
        'myCreate = New Crate

        myBox.Height = 5.0
        myBox.Width = 6.0
        myBox.Depth = 7.0

        myCreate.height = 2.5
        myCreate.width = 3.5
        myCreate.depth = 4.5

        Console.WriteLine(" Volume of myBox: {0}", myBox.volume())
        Console.WriteLine(" Volume of myCreate: {0}", myCreate.Volume())

    End Sub

    Public Class Box
        Public Height As Double
        Public Width As Double
        Public Depth As Double

        Public Sub New()

            Height = 0.0
            Width = 0.0
            Depth = 0.0

        End Sub

        Public Function Volume() As Double

            Return Height * Width * Depth

        End Function

    End Class

    Public Class Crate
        Inherits Box

        Public Quantity As Integer

        Public Sub New()

            Height = 0.0
            Width = 0.0
            Depth = 0.0
            Quantity = 0

        End Sub

    End Class
End Module
Old May 2nd, 2005, 09:12 PM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

I would also expect "Protected Friend" to behave the same as "Public" in this case as you are deriving Crate from Box. However, I very seldom use public class fields like this when building classes. I always go with the "private field, public accessor" approach. Perhaps the compiler has an issue with Protected class fields (i.e. a public Integer) vs a public/protected property that exposes a private class field.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using classes seymour_glass C# 1 April 26th, 2007 10:18 PM
HELP Problem With Classes nichola_x_rose ASP.NET 2.0 Professional 0 March 17th, 2007 07:56 AM
classes dhoward VB.NET 2002/2003 Basics 2 November 8th, 2006 10:35 AM
About Classes. wdw BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 29th, 2005 08:46 AM
Classes CodeMonkeys C# 3 August 18th, 2004 11:14 AM

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