|
-
Feb 15th, 2006, 05:21 PM
#1
Thread Starter
New Member
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
-
Feb 15th, 2006, 05:26 PM
#2
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...
-
Feb 15th, 2006, 05:34 PM
#3
Thread Starter
New Member
Re: Unhandled exception?
Blasted redim statement's.
Thanks alot. that stopped my error compleatly.
-
Feb 15th, 2006, 05:59 PM
#4
Re: Unhandled exception?
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|