Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An unhandled exception of type 'System.NullReferenceException' occurred 1

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
0
0
GB
Good afternoon, I am trying to learn VB.NET and have downloaded a 'hangman' project but it errors when it gets to the line
Code:
WrongGuessesLabel.Text = "Wrong Guesses: "

Variable 'WrongGuessesLabel' is used before it has been assigned a value. A null reference exception could result at runtime.

So I know where the problem is but don't know how to overcome it.

I've tried
Code:
Public WrongGuessesLabel As Label
to no avail.

Apologies if this seems like the most basic [no pun] of errors to overcome but it's extremely frustrating to fall at the first hurdle like this.

Many thanks,
DÇ$
 

Code:
Dim WrongGuessesLabel As Label
WrongGuessesLabel = [COLOR=#EF2929]New[/color] Label
WrongGuessesLabel.Text = ...



Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Hi Mark, I think I'd tried "New" when I was at work on Monday but had put it all in one line. Many thanks for this. I think the sample code is flawed in many ways but at least I got to play - and lose!!!

Many thanks,
DÇ$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top