Results 1 to 12 of 12

Thread: Object variable or With variable not set

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Angry Object variable or With variable not set

    Hi all,

    I've got a music player and I'm having a tough time fixing two errors. Whenever I try to run this line of code with a .mp4 or .wma file it will give me the error object variable or with variable not set.

    VB Code:
    1. duration = DirectShow.DirectShow_Position.duration

    Does anyone know why?

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Object variable or With variable not set

    What is DirectShow?

    VB Code:
    1. Dim DirectShow As ???
    you need to do:
    VB Code:
    1. Set DirectShow = New ???
    b4 you call your line of code.
    Unless DirectShow is a control.

    Woka

  3. #3

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Object variable or With variable not set

    thanks for the reply woka i was worried no one would answer this:

    but directshow is a modual for DirectX here is the code in the modual

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const MAX_VOLUME As Long = 100
    4. Private Const MAX_BALANCE As Long = 100
    5. Private Const MAX_SPEED As Long = 226
    6.  
    7. Public DirectShow_Event As IMediaEvent
    8. Public DirectShow_Control As IMediaControl
    9. Public DirectShow_Position As IMediaPosition
    10. Public DirectShow_Audio As IBasicAudio
    11. Public DirectShow_Video As IBasicVideo
    12. Public DirectShow_Video_Window As IVideoWindow
    13.  
    14. Public Video_Media As Boolean
    15. Public Video_Running As Boolean
    16. Public Fullscreen_Enabled As Boolean
    17. Public Fullscreen_Width As Long
    18. Public Fullscreen_Height As Long
    19.  
    20. Public moApp As Word.Application
    21. Private mbKillMe As Boolean
    22.  
    23.  
    24. Public Function DirectShow_Load_Media(File_Name As String) As Boolean
    25.  
    26.     On Error GoTo Error_Handler
    27.                
    28.         If Right(File_Name, 4) = ".mp3" Then
    29.                     Video_Media = False
    30.                             Set DirectShow_Control = New FilgraphManager
    31.             DirectShow_Control.RenderFile (File_Name)
    32.        
    33.             Set DirectShow_Audio = DirectShow_Control
    34.            
    35.             DirectShow_Audio.Volume = 0
    36.             DirectShow_Audio.Balance = 0
    37.        
    38.             Set DirectShow_Event = DirectShow_Control
    39.             Set DirectShow_Position = DirectShow_Control
    40.            
    41.             DirectShow_Position.Rate = 1
    42.            
    43.             DirectShow_Position.CurrentPosition = 0
    44.            
    45.         ElseIf Right(File_Name, 4) = ".mpeg" Or _
    46.                Right(File_Name, 4) = ".mpg" Or _
    47.                Right(File_Name, 4) = ".avi" Or _
    48.                Right(File_Name, 4) = ".mp4" Or _
    49.                Right(File_Name, 4) = ".wma" Or _
    50.                Right(File_Name, 4) = ".mov" Then
    51.                            Video_Media = True
    52.                            Set DirectShow_Control = New FilgraphManager
    53.             DirectShow_Control.RenderFile (File_Name)
    54.  
    55.             Set DirectShow_Audio = DirectShow_Control
    56.    
    57.             DirectShow_Audio.Volume = 0
    58.             DirectShow_Audio.Balance = 0
    59.  
    60.             If Fullscreen_Enabled = True Then
    61.                                 Set DirectShow_Video_Window = DirectShow_Control
    62.                 DirectShow_Video_Window.WindowStyle = CLng(&H6000000)
    63.                 DirectShow_Video_Window.Top = 0
    64.                 DirectShow_Video_Window.Left = 0
    65.                 DirectShow_Video_Window.Width = Fullscreen_Width
    66.                 DirectShow_Video_Window.Height = Fullscreen_Height
    67.                 DirectShow_Video_Window.Owner = frmMain.hwnd
    68.                
    69.             Else
    70.                 Set DirectShow_Video_Window = DirectShow_Control
    71.                 DirectShow_Video_Window.WindowStyle = CLng(&H6000000)
    72.                 DirectShow_Video_Window.Top = 0
    73.                 DirectShow_Video_Window.Left = 0
    74.                 DirectShow_Video_Window.Width = frmMain.ScaleWidth
    75.                 DirectShow_Video_Window.Height = frmMain.ScaleHeight
    76.                 DirectShow_Video_Window.Owner = frmMain.hwnd
    77.            
    78.             End If
    79.                     Set DirectShow_Event = DirectShow_Control
    80.             Set DirectShow_Position = DirectShow_Control
    81.            
    82.             DirectShow_Position.Rate = 1
    83.            
    84.             DirectShow_Position.CurrentPosition = 0
    85.                
    86.         Else
    87.                     GoTo Error_Handler
    88.        
    89.         End If
    90.  
    91.     DirectShow_Load_Media = True
    92.         Exit Function
    93. Error_Handler:
    94.  
    95.     DirectShow_Load_Media = False
    96.  
    97. End Function
    98.  
    99.  
    100. Public Function DirectShow_Play() As Boolean
    101.         On Error GoTo Error_Handler
    102.    
    103.     If Video_Media = True Then Video_Running = True
    104.         DirectShow_Control.Run
    105.  
    106.     DirectShow_Play = True
    107.         Exit Function
    108.  
    109. Error_Handler:
    110.    
    111.     DirectShow_Play = False
    112.  
    113. End Function
    114.  
    115. Public Function DirectShow_Stop() As Boolean
    116.  
    117.     On Error GoTo Error_Handler
    118.    
    119.     If Video_Media = True Then
    120.             Video_Running = False
    121.             Video_Media = False
    122.         End If
    123.         DirectShow_Control.Stop
    124.         DirectShow_Position.CurrentPosition = 0
    125.  
    126.     DirectShow_Stop = True
    127.         Exit Function
    128.  
    129. Error_Handler:
    130.  
    131.     DirectShow_Stop = False
    132.  
    133. End Function
    134.  
    135. Public Function DirectShow_Pause() As Boolean
    136.  
    137.     On Error GoTo Error_Handler
    138.    
    139.     DirectShow_Control.Stop
    140.  
    141.     DirectShow_Pause = True
    142.         Exit Function
    143. Error_Handler:
    144.    
    145.     DirectShow_Pause = False
    146.  
    147. End Function
    148.  
    149. Public Function DirectShow_Volume(ByVal Volume As Long) As Boolean
    150.  
    151.     On Error GoTo Error_Handler
    152.    
    153.     If Volume >= MAX_VOLUME Then Volume = MAX_VOLUME
    154.    
    155.     If Volume <= 0 Then Volume = 0
    156.    
    157.     DirectShow_Audio.Volume = (Volume * MAX_VOLUME) - 10000
    158.  
    159.     DirectShow_Volume = True
    160.         Exit Function
    161. Error_Handler:
    162.  
    163.     DirectShow_Volume = False
    164.  
    165. End Function
    166.  
    167. Public Function DirectShow_Balance(ByVal Balance As Long) As Boolean
    168.  
    169.     On Error GoTo Error_Handler
    170.    
    171.     If Balance >= MAX_BALANCE Then Balance = MAX_BALANCE
    172.    
    173.     If Balance <= -MAX_BALANCE Then Balance = -MAX_BALANCE
    174.    
    175.     DirectShow_Audio.Balance = Balance * MAX_BALANCE
    176.    
    177.     DirectShow_Balance = True
    178.         Exit Function
    179. Error_Handler:
    180.  
    181.     DirectShow_Balance = False
    182.  
    183. End Function
    184.  
    185. Public Function DirectShow_Speed(ByVal Speed As Single) As Boolean
    186.  
    187.     On Error GoTo Error_Handler
    188.  
    189.     If Speed >= MAX_SPEED Then Speed = MAX_SPEED
    190.    
    191.     If Speed <= 0 Then Speed = 0
    192.  
    193.     DirectShow_Position.Rate = Speed / 100
    194.  
    195.     DirectShow_Speed = True
    196.         Exit Function
    197.  
    198. Error_Handler:
    199.  
    200.     DirectShow_Speed = False
    201.  
    202. End Function
    203.  
    204. Public Function DirectShow_Set_Position(ByVal Hours As Long, ByVal Minutes As Long, ByVal Seconds As Long, Milliseconds As Single) As Boolean
    205.         On Error GoTo Error_Handler
    206.    
    207.     Dim Max_Position As Single
    208.         Dim Position As Double
    209.         Dim Decimal_Milliseconds As Single
    210.         'Keep minutes within range
    211.             Minutes = Minutes Mod 60
    212.        
    213.     'Keep seconds within range
    214.             Seconds = Seconds Mod 60
    215.        
    216.     'Keep milliseconds within range and keep decimal
    217.             Decimal_Milliseconds = Milliseconds - Int(Milliseconds)
    218.        
    219.         Milliseconds = Milliseconds Mod 1000
    220.        
    221.         Milliseconds = Milliseconds + Decimal_Milliseconds
    222.    
    223.     'Convert Minutes & Seconds to Position time
    224.             Position = (Hours * 3600) + (Minutes * 60) + Seconds + (Milliseconds * 0.001)
    225.    
    226.     Max_Position = DirectShow_Position.StopTime
    227.  
    228.     If Position >= Max_Position Then
    229.             Position = 0
    230.        
    231.         GoTo Error_Handler
    232.    
    233.     End If
    234.         If Position <= 0 Then
    235.             Position = 0
    236.        
    237.         GoTo Error_Handler
    238.    
    239.     End If
    240.         DirectShow_Position.CurrentPosition = Position
    241.    
    242.     DirectShow_Set_Position = True
    243.         Exit Function
    244. Error_Handler:
    245.  
    246.     DirectShow_Set_Position = False
    247.  
    248. End Function
    249.  
    250. Public Function DirectShow_End() As Boolean
    251.  
    252.     On Error GoTo Error_Handler
    253.    
    254.     If DirectShow_Loop = False Then
    255.             If DirectShow_Position.CurrentPosition >= DirectShow_Position.StopTime Then DirectShow_Stop
    256.    
    257.     End If
    258.         DirectShow_End = True
    259.         Exit Function
    260. Error_Handler:
    261.  
    262.     DirectShow_End = False
    263.  
    264. End Function
    265.  
    266. Public Function DirectShow_Loop() As Boolean
    267.  
    268.     On Error GoTo Error_Handler
    269.  
    270.     If DirectShow_Position.CurrentPosition >= DirectShow_Position.StopTime Then
    271.             DirectShow_Position.CurrentPosition = 0
    272.    
    273.     End If
    274.         DirectShow_Loop = True
    275.         Exit Function
    276. Error_Handler:
    277.  
    278.     DirectShow_Loop = False
    279.  
    280. End Function
    281.  
    282. Public Sub DirectShow_Shutdown()
    283.  
    284.     Set DirectShow_Video_Window = Nothing
    285.     Set DirectShow_Position = Nothing
    286.     Set DirectShow_Event = Nothing
    287.     Set DirectShow_Audio = Nothing
    288.     Set DirectShow_Control = Nothing
    289.  
    290. End Sub

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Object variable or With variable not set

    There si no DirectShow_Position in the module.
    Plus I cant see anywhere where you do something like:
    VB Code:
    1. Set DirectShow_Event = New IMediaEvent
    you must do this because you can use the DirectShow_Event object, or any of the other objects at the top of the module.

    Woof

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Object variable or With variable not set

    You do not need to use the module name, all you need is for the variable to be public (which it is).

    You can just use this:

    duration = DirectShow_Position.duration

  6. #6

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Object variable or With variable not set

    directshow_position is at the top

    VB Code:
    1. Public DirectShow_Event As IMediaEvent
    2. Public DirectShow_Control As IMediaControl
    3. Public DirectShow_Position As IMediaPosition
    4. Public DirectShow_Audio As IBasicAudio
    5. Public DirectShow_Video As IBasicVideo
    6. Public DirectShow_Video_Window As IVideoWindow

    This code will work for the .mp3 files so I don't know what the problem is!

  7. #7

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Object variable or With variable not set

    Quote Originally Posted by si_the_geek
    You do not need to use the module name, all you need is for the variable to be public (which it is).

    You can just use this:

    duration = DirectShow_Position.duration
    I changed that. But still I get the same error.


    Should I PM CVMichael or Jacob Roman on the matter?

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Object variable or With variable not set

    I assumed the issue was an initialisation one, as ".mp3" has a different piece of code... however the same is being done for DirectShow_Position either way, so I don't know what the problem is.

    I guess CVMichael or Jacob Roman may know the cause, it's worth a try.

  9. #9
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Object variable or With variable not set

    Actually, Jacob Roman has experience with Direct Show (I think), I only know how to work with DirectSound (for play & record wave, that's it).

    Anyways...

    I did not see the line "duration = DirectShow.DirectShow_Position.duration" from your original post in the code...
    What line exectly do you get the error ?

    Why don't you put line numbers for the code ? You can easily do that with MZTools, and use "Erl" to get the line number.
    Or simply comment the "On Error Go To ...", so that VB breaks at the line with the problem...
    Right now from the code, it looks like it's ignoring all errors... no MsgBox to show the error... just returning True/False...

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Object variable or With variable not set

    It looks a lot like JR's coding style.

  11. #11

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Object variable or With variable not set

    Yes, JR is the one who gave it to me. But I can't seem to get a hold of him about this problem.

  12. #12
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Object variable or With variable not set

    Is the ActiveMovie control type library added in your references? Sorry I couldn't answer ya right away. I was banned....again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width