VB6 Error Question

Object variable or With block not set

Page 1 of 1

3 Replies - 2719 Views - Last Post: 23 April 2007 - 11:52 AM Rate Topic: -----

#1 mbs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-April 07

VB6 Error Question

Posted 23 April 2007 - 01:16 AM

This bit of code gives me an error:
Object variable or With block not set

Private Sub mnuExit_Click()
ExitAndCloseNicely
End Sub

Private Sub ExitAndCloseNicely()
If p.PlayState = mpPlaying Then p.Stop
Set p = Nothing
Unload Me
End
End Sub



There is no where else in the code that
would set p=nothing.

Also, I don't get the error and the sound stops
properly if I close using the X in upper right corner.

Need help plz.

Is This A Good Question/Topic? 0
  • +

Replies To: VB6 Error Question

#2 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: VB6 Error Question

Posted 23 April 2007 - 06:16 AM

add if not p is nothing before your if p.playstate = mpplaying statement. What's happening is p is nver set to anything to begin with when the error occurs.
Was This Post Helpful? 0
  • +
  • -

#3 Traconesu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-April 07

Re: VB6 Error Question

Posted 23 April 2007 - 08:42 AM

View Posttody4me, on 23 Apr, 2007 - 06:16 AM, said:

add if not p is nothing before your if p.playstate = mpplaying statement. What's happening is p is nver set to anything to begin with when the error occurs.



I think the missing object variable is probably your p but it looks like you are calling your mediaplayer p and maybe did not change the name of the player to p but instead left it MediaPlayer1

If p.PlayState = mpPlaying Then p.Stop
p.FileName = ""
End

Or if you did not wish to change the name of the player object then:

If MediaPlayer1.PlayState = mpPlaying Then MediaPlayer1.Stop
MediaPlayer1.FileName = ""
End

The default name for the old media player is MediaPlayer1.
If you are using a newer media player then it will be called WindowsMediaPlayer1, and the properties you are tring to use to control your player will not be valid.
Was This Post Helpful? 0
  • +
  • -

#4 mbs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-April 07

Re: VB6 Error Question

Posted 23 April 2007 - 11:52 AM

Thanks for your time answering ;)
I'm sorry for not saying this before:
I project - reference msdxn.ocx

'In Gen Dec I use
Private WithEvents p As MediaPlayer.MediaPlayer

'And p is set in Form Load
'start intro sound
Set p = New MediaPlayer.MediaPlayer
p.Open gPath & "Sound\Intro.mp3"



Sound plays fine during first part of game,
p_endofstream loops it fine,
and when the intro part of game is done and
the action part begins sound stops properly
using only p.stop. So its definitely set already.

I get the error if I quit the game while the sound
is currently playing. And I don't know why.

That Exit procedure is the only place in the program
that sets it to nothing.

Any more ideas? LOL
Thanx again
MaryBeth
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1