Click to See Complete Forum and Search --> : Collections and keys


Dr_Michael
May 24th, 2001, 04:21 AM
for k = 1 to colArrayOfImages.Count
Debug.print "No=" & k
Debug.print "top=" & colArrayOfImages(k).Top
Debug.print "left=" & colArrayOfImages(k).Left
next k




I want also to print the key of each object, how is it possible? I cannot find the way.

Michael Vlastos
Automation Engineer
Intracom, Research & Development Division
Development Programmes Department
Athens, Greece

Cimperiali
May 24th, 2001, 05:20 AM
This is a workaround, and it may not fix your purpouse. But it is a hint you may improve. Trick is: as you cannot access that information, store it in tag property (or build your own property) to retrieve when you need.


Private colArrayOfImages As Collection
Private Sub Command1_Click()
Dim k As Integer
Dim myKey As String


Set colArrayOfImages = New Collection
With colArrayOfImages
For k = 0 To 3

myKey = myKey & "key" & k

.Add Image1, "key" & k

Next k

Image1.Tag = myKey
End With
For k = 1 To colArrayOfImages.Count
Debug.Print "No=" & k
Debug.Print "top=" & colArrayOfImages(k).Top
Debug.Print "left=" & colArrayOfImages(k).Left
Debug.Print Mid(colArrayOfImages(k).Tag, (k * 4) - 3, 4)
Next k
End Sub


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Cimperiali
June 4th, 2001, 02:28 AM
You may appreciate the dictionary object from Scripting Runtimes. It is a kind of collection, without indexes but with key. It has some limitations, but is quicker than collections. Most documentation refers to Vb script, but you can use dictionary in Vb with variables type which are not only variant.

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.