CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Collections and keys


    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

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Collections and keys

    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.

    Code:
    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.
    Last edited by Cimperiali; June 18th, 2004 at 10:05 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



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

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Collections and keys

    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.
    ...at present time, using mainly Net 4.0, Vs 2010



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

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