CDInfo - OnDoneCDInfo

Hi :slight_smile:
Please forgive me if this appears twice.

I’m using VB6 (SP5), XP Pro (SP2) and I have the latest version of nero installed. What I want to do is:
check for a cd / dvd in the drive
check if that is empty, rewritable etc…

Using the neroFilllesCOM example - I call the CDInfo and check the OnDoneCDInfo. If there is a cd / dvd in the drive I can get the info however if the drive is empty / open I get an error message. Here is my code, I think this must be a common problem and I have searched the list but I cannot figure it out can anyone please help.
Thanks in advance

Code:
Private Sub Burn_Click()

Dim drives As INeroDrives
Set drives = nero.GetDrives(NERO_MEDIA_CDR)
Set drive = drives(AvailableDevices.ListIndex)

MsgBox drive.DriveLetter

Call drive.CDInfo(NERO_READ_ISRC)

's = drive.CDRWErasingTime(True) ' Not rewritable
's = drive.EraseDisc(False, NERO_ERASE_MODE_DISABLE_EJECT)

End Sub

Private Sub drive_OnDoneCDInfo(ByVal pCDInfo As NEROLib.INeroCDInfo)

' If (pCDInfo = [B]Nothing[/B]) Then
        ' Error invalid use of object
' If (pCDInfo = [B]Null[/B]) Then
        ' Runtime error 91; Object variable or With block variable not set

    If (pCDInfo.Tracks.Count > 0) Then
        MsgBox "Is Writable: " & pCDInfo.IsWriteable
        MsgBox "MediaType: " & pCDInfo.MediaType
        MsgBox "Tracks: " & pCDInfo.Tracks.Count
    Else
        MsgBox "No Tracks:  CD / DVD Empty"
    End If

Else
    MsgBox "No CD / DVD"
End If

End Sub

When there is no disc in drive, pCDInfo is Nothing. You must check for Nothing before using the variable.

Thanks, In my code I have tried this

If (pCDInfo = Nothing) Then

and I keep getting the following error : Error invalid use of object

If (pCDInfo = Null) Then

and I get: Runtime error 91; Object variable or With block variable not set

You should use

If pCDInfo Is Nothing Then
.
.
.
End If

Mike

Actually, it should be something along the lines of:

If [b]Not[/b] (pCDInfo Is Nothing) Then 
. 
. 
. 
End If 

This might not be the exact VB syntax but the intention is to check that pCDInfo points to an object before trying to use it.

PGavin’s original post seems to imply that exactly the opposite has been used.

In actual fact, the NOT is irrelevant as long as the if statement is used correctly. For example:

If pCDInfo Is Nothing Then
MsgBox “No Disk Inserted, Please Insert Disk Then Try Again!”
NumExistingTracks = -1
DriveFinished = True
Exit Sub
End If

’ code for when disc is present

You are right but I was replying with the original poster’s code in mind. If you take a look at his first post, you will notice that the commented lines have reverse logic. That is why I insisted on NOT.

Hi, :slight_smile:
Thank you, (alexp and unison), very much for your help.