Results 1 to 3 of 3

Thread: Collection problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242

    Question

    Hello!

    I have a little problem with my collection object. When I try to add something to it, I get an error (91: Object variable or With variable not set.)
    Here's the code I use:
    Code:
    Type Vpr
        vVpra As Collection
        oOdgo As Collection
    End Type
    
    
    Public kVpr As Vpr
    
    Sub Add(str1, str2)
        With kVpr
            .vVpra.Add str1
            .oOdgo.Add str2
        End With
    End Sub
    What have I done wrong?
    As much as I know there should be no errors. Or I forgot something?
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    You need to declare a new instance of your collections
    Code:
    Type Vpr
        vVpra As New Collection 'Declare new instance
        oOdgo As New Collection 'of the collection object
    End Type
    
    
    Public kVpr As Vpr
    
    Sub Add(str1, str2)
        With kVpr
            .vVpra.Add str1
            .oOdgo.Add str2
        End With
    End Sub
    Hope this helps

    Shaun

    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Collections must be declared, too?
    I didn't know.

    Thanks.
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

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