[2008] Different Methods in class and ways to access them

Bozzy

Active member
Joined
Aug 31, 2007
Messages
27
Programming Experience
Beginner
Hello,

I have a class in Visual Basic 2008 that is used in two ways.

The first way it can be used is if you use it to create an instance. In this case, I want it to be able to access certain methods that I have defined. These can be methods such as, new obviously, and SetRange.

The second way it can be used, is as a way to use general functions in it. Because this is a light, such a function might be SetAmbient etc...

Is there a way that I can hide the SetAmbient function when it is being called by an instance, but show it when it is simply been called as a general command.
VB.NET:
Light.SetAmbient

And then, show all the other methods that are available to be called from an instance:

VB.NET:
Dim Light1 as New Light
Light1.SetRange


Thanks,
Bozzy
 
Location property is of type Point. Point is a structure that among many members has for example X and Y properties. Write a keyword in your help index and you usually find exactly that information.
 
I'm really not getting your explanations or the MSDN stuff at all. Crikey, I must be annoying by now, sorry.
 
Bozzy : i think you just need to understand some of the basic terminlogy.

Mainly, you have to understand that a property returns an object of a certain type.

Location is a PROPERTY and it returns an object of type Point. Point is a type that has two properties inside it : X and Y, and they return integers.

that's how you can get Location.X

by typing in Location, you are asking for the Location property to return to you a Point. By typing in .X, you are asking for when the Location property has returned the point, to look inside this object of type Point and return the X property.
 
What is a type exactly?
type Point

But, that was helpful.

I have tried this:
VB.NET:
    Structure Point
        ReadOnly Property X() As Integer
            Get
                Return 5
            End Get
        End Property
    End Structure

    Property Location() As Point
        Get
            Return Point
        End Get
        Set(ByVal value As Point)

        End Set
    End Property

But it gave an error
Error 2 'Point' is a type and cannot be used as an expression. C:\Users\Richard\AppData\Local\Temporary Projects\ConsoleApplication1\Module1.vb 17 20 ConsoleApplication1
 
What is a type exactly?

But, that was helpful.

I have tried this:
VB.NET:
    Structure Point
        ReadOnly Property X() As Integer
            Get
                Return 5
            End Get
        End Property
    End Structure

    Property Location() As Point
        Get
            Return Point
        End Get
        Set(ByVal value As Point)

        End Set
    End Property

But it gave an error

Hi

I think now we're getting somewhere. A type is a class or a structure. An object is an instance of the class or a structure.

A Property will return an instance of the specified type.

So in your Location property you've written above, the "As Point" bit says that you are returning an object that is of type Point.

The problem with your code through is that you are return a Type as opposed to an instance of that type.

VB.NET:
    private mPoint as new Point

    Structure Point
        ReadOnly Property X() As Integer
            Get
                Return 5
            End Get
        End Property
    End Structure

    Property Location() As Point
        Get
            Return mPoint
        End Get
        Set(ByVal value As Point)
            mPoint = value
        End Set
    End Property

that's what you would need to do.
 
Thanks, it works and I now get it :D

Oh, and one more thing:

VB.NET:
Private Declare Function lwLoadSound Lib "engine.dll" (ByVal filename As String) As Integer

When I try to do:

#Const engine = "engine.dll"

and use that instead, then it says
String constant expected







As well as this:

When I try to do this:
VB.NET:
Private Class c_Channel
        Inherits Sound


    End Class

    Property Channel() As c_Channel
        Get
            Return Me.vChannel
        End Get
        Set(ByVal value As c_Channel)
            Me.vChannel = value
        End Set
    End Property

It says:

Error 8 'Channel' cannot expose type 'c_Channel' in namespace 'Leadwerks_Engine___OOP' through class 'Sound'.

I don't want the person using my class library to see the c_Channel class, but just the Channel Property
 
Last edited:
That doesn't make any sense. How can they see the Channel property if they can't see its type? How can you get a c_Channel object if you don't know what a c_Channel object is?
 
I simply want it to be an internal kind of function that is not displayed on intellisense, you see. But, I do want it accessable for functions inside the class that it is in.
 
By the looks of your code you must have declared the c_Channel class within another class, otherwise it could not be Private. In that case your Channel property has to be Private too. You haven't specified any access level on that property. That's legal but poor practice. You should ALWAYS specify an access level for EVERYTHING. Class methods are Public by default, so you're trying to expose a Private type via a Public property. That is simply not logical. If the type is supposed to be Private then the property should be private too. If the property is supposed to be Public then the type should be Public too.
 
Back
Top