 |
|
 |
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: Property arrays???
You can easily implement this with classes. Example
clsAircraft code
Option Explicit
Private m_Projection As clsProjection
Public Property Get Projection() As clsProjection
Projection = m_Projection
End Property
Public Property Set Projection(Value As clsProjection)
m_Projection = Value
End Property |
clsProjection code
Option Explicit
Private m_Height As Long
Private m_X As Long
Private m_Y As Long
Private m_Date As Date
Public Property Get Height() As Long
Height = m_Height
End Property
Public Property Let Height(Value As Long)
m_Height = Value
End Property
Public Property Get X() As Long
X = m_X
End Property
Public Property Let X(Value As Long)
m_X = Value
End Property
Public Property Get Y() As Long
Y = m_Y
End Property
Public Property Let Y(Value As Long)
m_Y = Value
End Property
Public Property Get Time() As Date
Time = m_Time
End Property
Public Property Let Time(Value As Date)
m_Time = Value
End Property |
and this is how it will look from from code
Dim Aircraft As New clsAircraft
Aircraft.Projection.Height=100 |
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
17-06-2005 at 02:20 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: Property arrays???
Aha, now I got you.
quote: In the example u've given, can i define the m_Projection as an array like this:
Private m_Projection(99) As clsProjection
Yes, you can create an array of objects, but you need to specify New keyword.
quote: Moreover can classes have a visual image? Like a circle, or something on the form (just like controls can..)?
No, class doesnt have an interface.
quote: Aircraft.Projection.Height(99) = 150
This is not the same as creating an array of objects. If you are creating an array of objects, like
| dim a(10) as new clsprojection |
then it means you will have 10 projection objects, but each wil have only one value for height property.
If you want to create a property array, which is a different thing, then you would do it like this
clsprojection code
Option Explicit
Private m_Height(10) As Long
Public Property Get Height(index As Long) As Long
Height = m_Height(index)
End Property
Public Property Let Height(index As Long, Value As Long)
m_Height(index) = Value
End Property |
then you can have multiple (10) values for height
dim p as new clsprojection
p.height(0)=10
p.height(1)=15
p.height(2)=20
' etc etc |
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
18-06-2005 at 12:59 AM |
|
|
misterxed Level: VB Lord

 Registered: 12-06-2005 Posts: 151
|
Re: Property arrays???
Thanx for the help Goran... but i'm still stuck!!!
Heres the situation now:
U told me that the problem cud b solved by using class objects. I made the Projection class jsut as u sed
quote:
clsprojection code
Option Explicit
Private m_Height(10) As Long
Public Property Get Height(index As Long) As Long
Height = m_Height(index)
End Property
Public Property Let Height(index As Long, Value As Long)
m_Height(index) = Value
End Property
(and the rest of the properties as well (x, y, and date...)
but i didnt make the Aricraft class. Instead i've made an Activex Control, and put the same code as u sed to put in the aircraft class (cuz i need a visual interface for the aircraft)
heres the problem:
it works fine when i'm running the app, but when i try to add values to the height, x,y, & date arrays, it gives the following error:
Runtime error 91
Object Variable or With block variable not set
When i click on Debug, it goes to:
| Property Get Projection() as clsProjection |
in the Aircraft activex, and when i point to the
| Projection = m_Projection |
line, it says Projection = Nothing
Help PLEASE
____________________________
lOsT...
|
|
18-06-2005 at 08:14 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: Property arrays???
Sorry, it was my mistake, didnt have time to test the code. I forgot class initialize event:
add this code to clsAircraft
private sub class_initialize()
set m_projection=new clsprojection
end sub
' and also correct this line of code
Public Property Get Projection() As clsProjection
Set Projection = m_Projection
End Property |
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
18-06-2005 at 08:55 PM |
|
|
|
|
 |
 |