Array as a Property of an Object, and Collection 
Author Message
 Array as a Property of an Object, and Collection

Please, if anyone could help, it would be much appreciated - Thanks

If anyone could help it would be greatly appreciated. Ive been reading the vb
newsgroups and have discovered many techniques that I have benifited from.
I an a VB4 structural type programmer who has moved to VB6 and OOP's.

My progression of learning is by reading
"John Smiley's - Learn to program Objects with VB6", then
"Peter Wright's - Beginning VB6 Objects", and finished with
"Technology Press - Visual Basic 6 Object Orientated Programming - Gold Book".

I found all these books, in that order as very helpful,
and also The Object-Oreintated Thought Process - The Authoritative Solution -
SAMS Pub., as a very good introduction. Well thats what I have been reading,
and now its time to put it into practice.........

Question regarding an array as a property of an object, and inturn
this object will form an item in a collection.

What I am simply doing is passing a variable to an object, and requesting that
the object return all my required details in an array, for easier handling.
The intention of this is to obtain "item codes, assigned lengths of material
and quantities. These will the be either printed to advice the workshop of the
cutting list, or the pricing process to allocate cost to the material."

What my problem is that I can extract the array components when directly
requesting from the object, but when the object is passed to a collection, and
I make request from the collection, it fails, sorry I fail.

To overcome this I have assigned a local array and passed the collection item
object member array to it from the collection.
To best describe this the following simplified example code has been included.

I have tried many ways, my intention is to create a collection object, rather
that handle the collection at form level,
but until I resolve , I cant proceed. I would apprecite your comments.

Regards

Tony (from the land downunder)

'The following is the ClassModule for "clsSectionHeight"
Option Explicit
Option Base 1
Private m_Height As Integer
Private m_HeightOld As Integer
Dim m_Detail(5, 3) As Variant

Public Property Get Height() As Integer
        Call Calc_Details_Height
    Height = m_Height
End Property

Public Property Let Height(ByVal vNewValue As Integer)
If vNewValue > 0 Then
    If m_HeightOld <> vNewValue Then
        m_Height = vNewValue
        Call Calc_Details_Height
        m_HeightOld = m_Height
    End If
    Else
       MsgBox "Height requires a value greater than 0"
End If
End Property

'Intend to remove Let procedure and make details as read only

Public Property Let Details(ByVal m_Detail As Variant)
m_Detail = Details()
End Property

Public Property Get Details() As Variant
Details = m_Detail()
End Property

Public Sub Calc_Details_Height()
m_Detail(1, 1) = "D4951"
m_Detail(1, 2) = m_Height
m_Detail(1, 3) = 2
m_Detail(2, 1) = "D1900"
m_Detail(2, 2) = m_Height - 24
m_Detail(2, 3) = 1
m_Detail(3, 1) = "D1359"
m_Detail(3, 2) = m_Height - 24
m_Detail(3, 3) = 1
m_Detail(4, 1) = "D1349"
m_Detail(4, 2) = m_Height - 53
m_Detail(4, 3) = 1
m_Detail(5, 1) = "D1352"
m_Detail(5, 2) = m_Height - 53
m_Detail(5, 3) = 1
End Sub

Private Sub Class_Initialize()
Debug.Print "Object Intitialized..."
End Sub

Private Sub Class_Terminate()
Debug.Print "Object Died......."
End Sub

'End of Class Module

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'the following is one option of the form details
'the form contains a collection of the objects as added

Option Explicit
Option Base 1

Dim objMyHeight As clsSectionHeight
Dim ColCount As Variant
Dim colOfObjects As New Collection

Private Sub Command1_Click()

'start object and assign height
Set objMyHeight = New clsSectionHeight
objMyHeight.Height = Val(text1) 'height added to textbox

End Sub

Private Sub Command2_Click()
Dim intCount1 As Integer
Dim intCount2 As Integer 'not used, will do later

   'Clear listbox and add details for viewing
List1.Clear
List1.AddItem objMyHeight.Height

' for test purpose only the first column of array is called
'this workssince the array call is made directly to the object

For intCount1 = LBound(objMyHeight.Details) To UBound(objMyHeight.Details)
    List1.AddItem objMyHeight.Details(intCount1, 1)
Next intCount1

End Sub

Private Sub Command3_Click()

'add to the collection
ColOfObjects.Add objMyHeight

ColCount = ColCount + 1

Set objMyHeight = Nothing

End Sub

Private Sub Command4_Click()
Dim intCount1 As Integer
Dim intCount2 As Integer

List2.Clear
For intCount1 = 1 To ColOfObjects.Count
        List2.AddItem ColOfObjects(intCount1).Height

'xxxxxxxxxxxxxx The following block does not work
,xxxxxxxxxxxxxx will not add array to listbox2
For intCount2 = LBound(ColOfObjects(intCount1).Details) To
UBound(ColOfObjects(intCount1).Details)
    List2.AddItem ColOfObjects(intCount1).Details(intCount2, 1)
Next intCount2

'xxxxxxxxxxxxxx The following block does work
'xxxxxxxxxxxxxx but this is not my preference
Dim answer1() As Variant
answer1() = ColOfObjects(intCount1).Details()

For intCount2 = LBound(answer1) To UBound(answer1)
    List2.AddItem answer1(intCount2, 1)
Next intCount2

Next intCount1

End Sub

Private Sub Form_Load()

Set ColOfObjects = New Collection
ColCount = 1

End Sub

______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.*-*-*.com/



Tue, 03 Feb 2004 15:42:35 GMT  
 Array as a Property of an Object, and Collection
Turn your array elements into a class then  create a class that handles the
elements class as a collection.
the add that class as a property of the clsSectionHeight.
See the expample House Of Bricks that i believe is in the Documentation for
VB on the Developer Network disk.

three classes
clsElem = elements
clsElements = class that encapsulates a collection
   implements Add Item Count etc of a collection

dim cElem as clsElem
dim cSH as new clsSectionHeight

set cElem = new clsElem
cElem.Property1 = "KeyValue1"
cElem.Property2 =  123.662"

cSH.Elements.Add(cELM,cELM.property1)


Quote:
> Please, if anyone could help, it would be much appreciated - Thanks

> If anyone could help it would be greatly appreciated. Ive been reading the
vb
> newsgroups and have discovered many techniques that I have benifited from.
> I an a VB4 structural type programmer who has moved to VB6 and OOP's.

> My progression of learning is by reading
> "John Smiley's - Learn to program Objects with VB6", then
> "Peter Wright's - Beginning VB6 Objects", and finished with
> "Technology Press - Visual Basic 6 Object Orientated Programming - Gold
Book".

> I found all these books, in that order as very helpful,
> and also The Object-Oreintated Thought Process - The Authoritative
Solution -
> SAMS Pub., as a very good introduction. Well thats what I have been
reading,
> and now its time to put it into practice.........

> Question regarding an array as a property of an object, and inturn
> this object will form an item in a collection.

> What I am simply doing is passing a variable to an object, and requesting
that
> the object return all my required details in an array, for easier
handling.
> The intention of this is to obtain "item codes, assigned lengths of
material
> and quantities. These will the be either printed to advice the workshop of
the
> cutting list, or the pricing process to allocate cost to the material."

> What my problem is that I can extract the array components when directly
> requesting from the object, but when the object is passed to a collection,
and
> I make request from the collection, it fails, sorry I fail.

> To overcome this I have assigned a local array and passed the collection
item
> object member array to it from the collection.
> To best describe this the following simplified example code has been
included.

> I have tried many ways, my intention is to create a collection object,
rather
> that handle the collection at form level,
> but until I resolve , I cant proceed. I would apprecite your comments.

> Regards

> Tony (from the land downunder)

> 'The following is the ClassModule for "clsSectionHeight"
> Option Explicit
> Option Base 1
> Private m_Height As Integer
> Private m_HeightOld As Integer
> Dim m_Detail(5, 3) As Variant

> Public Property Get Height() As Integer
>         Call Calc_Details_Height
>     Height = m_Height
> End Property

> Public Property Let Height(ByVal vNewValue As Integer)
> If vNewValue > 0 Then
>     If m_HeightOld <> vNewValue Then
>         m_Height = vNewValue
>         Call Calc_Details_Height
>         m_HeightOld = m_Height
>     End If
>     Else
>        MsgBox "Height requires a value greater than 0"
> End If
> End Property

> 'Intend to remove Let procedure and make details as read only

> Public Property Let Details(ByVal m_Detail As Variant)
> m_Detail = Details()
> End Property

> Public Property Get Details() As Variant
> Details = m_Detail()
> End Property

> Public Sub Calc_Details_Height()
> m_Detail(1, 1) = "D4951"
> m_Detail(1, 2) = m_Height
> m_Detail(1, 3) = 2
> m_Detail(2, 1) = "D1900"
> m_Detail(2, 2) = m_Height - 24
> m_Detail(2, 3) = 1
> m_Detail(3, 1) = "D1359"
> m_Detail(3, 2) = m_Height - 24
> m_Detail(3, 3) = 1
> m_Detail(4, 1) = "D1349"
> m_Detail(4, 2) = m_Height - 53
> m_Detail(4, 3) = 1
> m_Detail(5, 1) = "D1352"
> m_Detail(5, 2) = m_Height - 53
> m_Detail(5, 3) = 1
> End Sub

> Private Sub Class_Initialize()
> Debug.Print "Object Intitialized..."
> End Sub

> Private Sub Class_Terminate()
> Debug.Print "Object Died......."
> End Sub

> 'End of Class Module

> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 'the following is one option of the form details
> 'the form contains a collection of the objects as added

> Option Explicit
> Option Base 1

> Dim objMyHeight As clsSectionHeight
> Dim ColCount As Variant
> Dim colOfObjects As New Collection

> Private Sub Command1_Click()

> 'start object and assign height
> Set objMyHeight = New clsSectionHeight
> objMyHeight.Height = Val(text1) 'height added to textbox

> End Sub

> Private Sub Command2_Click()
> Dim intCount1 As Integer
> Dim intCount2 As Integer 'not used, will do later

>    'Clear listbox and add details for viewing
> List1.Clear
> List1.AddItem objMyHeight.Height

> ' for test purpose only the first column of array is called
> 'this workssince the array call is made directly to the object

> For intCount1 = LBound(objMyHeight.Details) To UBound(objMyHeight.Details)
>     List1.AddItem objMyHeight.Details(intCount1, 1)
> Next intCount1

> End Sub

> Private Sub Command3_Click()

> 'add to the collection
> ColOfObjects.Add objMyHeight

> ColCount = ColCount + 1

> Set objMyHeight = Nothing

> End Sub

> Private Sub Command4_Click()
> Dim intCount1 As Integer
> Dim intCount2 As Integer

> List2.Clear
> For intCount1 = 1 To ColOfObjects.Count
> List2.AddItem ColOfObjects(intCount1).Height

> 'xxxxxxxxxxxxxx The following block does not work
> ,xxxxxxxxxxxxxx will not add array to listbox2
> For intCount2 = LBound(ColOfObjects(intCount1).Details) To
> UBound(ColOfObjects(intCount1).Details)
>     List2.AddItem ColOfObjects(intCount1).Details(intCount2, 1)
> Next intCount2

> 'xxxxxxxxxxxxxx The following block does work
> 'xxxxxxxxxxxxxx but this is not my preference
> Dim answer1() As Variant
> answer1() = ColOfObjects(intCount1).Details()

> For intCount2 = LBound(answer1) To UBound(answer1)
>     List2.AddItem answer1(intCount2, 1)
> Next intCount2

> Next intCount1

> End Sub

> Private Sub Form_Load()

> Set ColOfObjects = New Collection
> ColCount = 1

> End Sub

____________________________________________________________________________
__
Quote:
> Posted Via Binaries.net = SPEED+RETENTION+COMPLETION =

http://www.binaries.net


Tue, 03 Feb 2004 23:21:48 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Object Properties, Array Properties

2. Array (or any indexed collection) properties in Classes.

3. Arrays in Collections, Arrays in Arrays

4. Sorting user-defined objects - Collection vs. array

5. Storing objects in collection/array

6. Array/Collection of objects declared WithEvents

7. Array/Collection of objects declared WithEvents

8. send/receive collections/arrays of com-objects in functions

9. Object Array vs. Collection

10. retrieving textboxes properties in a collection or OLEobjects object

11. How to get the object a collection property is located in

12. Help: Using InvokeMethod to Set property of object in a collection

 

 
Powered by phpBB® Forum Software