Results 1 to 3 of 3

Thread: Which type does Collection object accept?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120

    Which type does Collection object accept?

    Hi,

    Why does the followin code says "Type missmatch "?

    If c.Container.Caption = "Info" Then
    If TypeOf c Is ComboBox Then valColl.Add (c.Text), c.Index
    If TypeOf c Is label Then labelColl.Add c.Caption, c.Index
    If TypeOf c Is TextBox Then valColl.Add c.Text, c.Index
    End If
    Next c


    These follwing 3 lines give the error "Type missmatch"

    If TypeOf c Is ComboBox Then valColl.Add (c.Text), c.Index
    If TypeOf c Is label Then labelColl.Add c.Caption, c.Index
    If TypeOf c Is TextBox Then valColl.Add c.Text, c.Index


    Thanks

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    The second argument to the Add method of a Collection object is the Key.
    Key must be a string. You're adding the Index of the object.
    You must explicitly change that to a string
    VB Code:
    1. If TypeOf c Is ComboBox Then valColl.Add (c.Text), [b]CStr(c.Index)[/b]
    Or use the Index argument of the collection object which is the third argument of the Add method.

    Best regards

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Posts
    120
    Thanks Joacim Andersson
    it worked !

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