Results 1 to 4 of 4

Thread: Unhandled exception?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    6

    Unhandled exception?

    I've been working on a very basic windows form program. using VB.net. when I run the program I get the error: System.NullReferenceException
    with the lines of code:
    Private Sub CreatetxtBox(ByVal truckCurrent As Integer, ByVal deliverycurrent As Integer, ByVal pnt As Point)

    txtTruck(truckCurrent, deliverycurrent) = New TextBox
    txtTruck(truckCurrent, deliverycurrent).Visible = True
    txtTruck(truckCurrent, deliverycurrent).Size = New System.Drawing.Size(txtboxwidth, txtboxhight)
    txtTruck(truckCurrent, deliverycurrent).Location = pnt

    End Sub

    my variables are something as folows:
    txtboxwidth = 75
    txtboxhight = 40
    truck current = 0 to 6
    delivery current = 0 to 5

    if anyone can tell me, or point me in the right dirrection on this, I would be very thankful

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Unhandled exception?

    How did you declare your txtTruck array? Are you trying to set up some kind of control array? Because you cannot do it the same way as you did in VB6. You have to add your controls to some sort of collection or an array in order to reference them by an index.

    If you didnt declare the initial size of your array, you have to Redim the array (with the preserve keyword) in order to hold the next value...

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    6

    Re: Unhandled exception?

    Blasted redim statement's.

    Thanks alot. that stopped my error compleatly.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Unhandled exception?

    Quote Originally Posted by gigemboy
    If you didnt declare the initial size of your array, you have to Redim the array (with the preserve keyword) in order to hold the next value...
    If you didn't specify the initial size of the array then there is nothing to preserve. There's not even an array, never mind any elements. Having said that, it might not be a bad idea to use Preserve by default and then only omit it when you specifically want erase the existing data. I'd guess that you are less likely to make mistakes that way.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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