CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: CLASS TUTORIALS

  1. #1
    Join Date
    Sep 2001
    Location
    Sydney
    Posts
    14

    CLASS TUTORIALS

    can anybody just show me where i can get a simple class demonstration, i know how to reference classes with forms, i just need some help with let and get statements, if there is a simple example out there like just adding 2 numbers together, it will help me alot, thanx alot

    YAY MY FIRST POST LOL

    --==|3Lad3==--

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: CLASS TUTORIALS

    Not sure where they aren but they're out there somewhere. I'll just give a quick example:

    ' in a class module, let's say Car
    private iTires as Integer
    private sColor as string
    private oDriver as Object

    ' to give a value to Tires
    public property let Tires(Amount as Integer)
    iTyres = Amount
    End property

    ' to get the value of Tires
    public property get Tires() as Integer
    Tires = iTires
    End property

    ' to give a value to Color
    public property let Color(sClr as string)
    sColor = sClr
    End property

    ' to get the value of Color
    public property get Color() as string
    Color = sColor
    End property

    ' to give a value to CarDriver
    public property set CarDriver(oDrv as Driver)
    set oDriver = oDrv
    End property

    ' to get the value of CarDriver
    public property get CarDriver() as Driver
    set Driver = oDriver
    End property



    What we have here is a simple class, nl a car. A car has an amount of tires, a color and a driver. The first is an integer, the second a string, the last an object of the type driver (which could be another class we already made). The strihng and integer are easy to handle. We use LET to set it, and GET to get it. Driver however, is an object, we use SET to set it, and GET to get it. When using the object, we will need to use the SET statement.

    ' somewhere in code
    Dim myCar as new Car
    Dim SomeDriver as Driver

    ' to assing values
    myCar.Tires = 4
    myCar.Color = "Black"
    set myCar.Driver = SomeDriver

    ' to retrieve values
    Dim myColor as string, myTires as Integer, myDriver as Driver
    myColor = myCar.Color
    myTires = myCar.Tires
    set myDriver = myCar.Driver



    Note that when using Driver, you will need to use the Set statement.


    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured