Welcome to Dream.In.Code
Become a VB Expert!

Join 137,229 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,890 people online right now. Registration is fast and FREE... Join Now!




NullReference Error

 
Reply to this topicStart new topic

NullReference Error

orangeslide8
10 Feb, 2007 - 05:20 PM
Post #1

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
ok so heres a code that has a nullrefrence Error and i can't figure out why.
[code]
Dim Chips25() as PictureBox
Dim Numberof25s as integer
Chips25(numberof25s) = New Picturebox
chips25(Numberof25s).visible = true
User is offlineProfile CardPM
+Quote Post

Jayman
RE: NullReference Error
10 Feb, 2007 - 05:40 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You have not assigned a value to Numberof25s, therefore it is Null. You have to assign a value to a variable before you can use it.
User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: NullReference Error
11 Feb, 2007 - 05:35 AM
Post #3

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(jayman9 @ 10 Feb, 2007 - 06:40 PM) *

You have not assigned a value to Numberof25s, therefore it is Null. You have to assign a value to a variable before you can use it.

but its a picture box what value should I assign To it?
john
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: NullReference Error
11 Feb, 2007 - 07:19 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Which line are you getting the error for? I can't remember if VB is case sensitive or not but you have spelled the variable name both with a capital and without.
User is online!Profile CardPM
+Quote Post

Jayman
RE: NullReference Error
11 Feb, 2007 - 10:20 AM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Sorry I gave you a wrong answer in my first post. This has nothing to do the Numberof25s variable. Thats what I get for giving a hasty response. VB.NET implicitly assigns a value to primitive data type variables if they are not assigned a value to begin with.

But it has to do with the fact that you are declaring an array of controls. You need to declare explicitly how many controls you want in your array before you can instantiate a new control.

Currently you have declared an array of PictureBoxes, but you never tell it how many controls to create.

For example put a number inside the constructor of the array of controls declaring how many you want.
CODE

Dim Chips25(10) As PictureBox

Dim Numberof25s As Integer
Chips25(Numberof25s) = New PictureBox
Chips25(Numberof25s).Visible = True

User is offlineProfile CardPM
+Quote Post

orangeslide8
RE: NullReference Error
11 Feb, 2007 - 11:30 AM
Post #6

D.I.C Head
Group Icon

Joined: 29 Dec, 2006
Posts: 190



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(jayman9 @ 11 Feb, 2007 - 11:20 AM) *

Sorry I gave you a wrong answer in my first post. This has nothing to do the Numberof25s variable. Thats what I get for giving a hasty response. VB.NET implicitly assigns a value to primitive data type variables if they are not assigned a value to begin with.

But it has to do with the fact that you are declaring an array of controls. You need to declare explicitly how many controls you want in your array before you can instantiate a new control.

Currently you have declared an array of PictureBoxes, but you never tell it how many controls to create.

For example put a number inside the constructor of the array of controls declaring how many you want.
CODE

Dim Chips25(10) As PictureBox

Dim Numberof25s As Integer
Chips25(Numberof25s) = New PictureBox
Chips25(Numberof25s).Visible = True


is there a way to have a variable with no parameter thats why i put the () i thought that meant no parameter
thnx
john

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: NullReference Error
11 Feb, 2007 - 11:32 AM
Post #7

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
The () denote an array - meaning that you have declared many of them. Are you trying to create a multitude of them, or only one? If more than one, do you need to resize the array during runtime?
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:12PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month