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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error 91: Object Variable or With Block variable not set

Status
Not open for further replies.

mbrink

Technical User
Jul 5, 2002
13
US
I am making a simple game, and am having difficulty using a small form to set the name of the player. The name variable is part of a class called 'Player' and is currently set as a public variable (happened during my debugging process). the player-class variable Player1 is declared as public on the form frmDungeonQuest, which is the first form loaded and only get hidden, never unloaded. Here's the code for the name input button:

Dim temp As String
temp = txtName
frmDungeonQuest.Player1.Name = temp
'error occurs in above line
Counter = Counter + 1
If (frmDungeonQuest.NoPlayers = 1) Then
frmDungeonQuest.Show
Me.Hide
End If

Every time I get the RunTime error 91. Any Ideas?
 
Put the statement

Code:
Load frmDungeonQuest
[code]

before 
[code]
frmDungeonQuest.Player1.Name = temp
 
That didn't have any affect. Like I had said, frmDungeonQuest is the form the project starts in and is only hidden, not unloaded.
 
oh,,, iam sorry,, miss understood you

how are you declaring your Player1 variable?

like this:

Code:
Public Player1 As Player

if you do this then before you reference your Player1 variable you have to do this:

Set Player1 = New Player

or you can declare like this:

Code:
Public Player1 As [b]New[/b] Player

Again,,, sorry for the misunderstanding
 
Also,,, here is some excellent discussion on using the New[/] keyword

thread222-297780
 
That silly little new statement was it. That's an interesting concept...declaring a variable, yet it doesn't completely create it.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top