Click to See Complete Forum and Search --> : CLASS TUTORIALS


|3Lad3
September 30th, 2001, 11:29 AM
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 :D

YAY MY FIRST POST LOL

--==|3Lad3==--

Cakkie
September 30th, 2001, 04:33 PM
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
slisse@planetinternet.be

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