Results 1 to 3 of 3

Thread: Control Instance Error [Resolved]

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Control Instance Error [Resolved]

    For some reason, when i use the following line of code

    VB Code:
    1. Dim SelectedComputers() as String
    2. ...
    3. clstAddresses.CheckedItems.CopyTo(SelectedComputers, 0)

    I get an error saying that the Object reference is not set to an instance of an object. Now the most confusing part about it is that i have other code that is used before it that works fine

    VB Code:
    1. If clstAddresses.CheckedItems.Count = 0 Then

    I have another prog that uses code like the first code sample that works fine but that one doesn't. The only thing i can think of is that it must have something to do with the inherited forms feature, but the control is local to that form and anything else but the copyto thing seems to work fine. Any Ideas?
    Last edited by Ideas Man; Mar 5th, 2004 at 09:40 PM.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    CopyTo copies a collection or array to another array. The destination array must already be initialized with enough elements to fit the Copied items.
    VB Code:
    1. Dim SelectedComputers(clstAddresses.CheckedItems.Count-1) as String
    2. clstAddresses.CheckedItems.CopyTo(SelectedComputers, 0)

  3. #3

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    Thanks Edneeis that's what was wrong. After looking at my other code again, I noticed that line, lol, must be tired.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

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