bugs >> How to detect that NO CD exists in the CHOSEN DRIVE

by cG11ZA » Fri, 02 Jun 2006 23:24:03 GMT

Hi,

I have a DriveList Box ( drvChoose) and a Directory ListBox ( dirDirect)
in my ActiveX control. When the users choose a drive, then the directoryList
box changes to display the directories of that drive. This works fine. BUt
the problem is that when no CD exists in the CD ROM drive and users choose
that drive, then my program fails. It shows diagnoal black lines across my
activeX control.

What code do I need to add so that when no CD/ DVD exists in the CD drive
and if user selects that drive, then an error message is displayed which says
there is no CD/ DVD in this drive. Please insert it to continue.

Below is the code I am using.

Private Sub drvChoose_Change()

dirDirect.Path = drvChoose.Drive '--WHEN NO CD in the CHOSEN DRIVE, It
FAILS

End Sub

Any help will be appreciated.

Thanks
--
pmud


bugs >> How to detect that NO CD exists in the CHOSEN DRIVE

by Karl E. Peterson » Sat, 03 Jun 2006 01:06:59 GMT





You need to use error-trapping! Here's an example from a little UserControl
I put together that ties all three native file controls together:

Private Sub Drive1_Change()
Static Busy As Boolean

' Avoid recursion.
If Not Busy Then
' Watch out for invalid/unavailable drives!
On Error Resume Next
Dir1.Path = Drive1.Drive
Select Case Err.Number
Case 0
' Let user know drive was changed.
RaiseEvent DriveChanged(Drive1.Drive)
' Remember this as a "good" drive.
m_LastGoodDrive = Drive1.Drive
Case 68
' Bad choice, stick with what was.
Err.Clear
RaiseEvent DeviceUnavailable(Drive1.Drive)
Busy = True
Drive1.Drive = m_LastGoodDrive
Busy = False
Case Else
' Huh?
Debug.Print Err.Number, Err.Description
End Select
End If
End Sub

Later... Karl
--
Working without a .NET?
http://classicvb.org/





bugs >> How to detect that NO CD exists in the CHOSEN DRIVE

by cG11ZA » Sat, 03 Jun 2006 01:21:02 GMT

Hi Karl,

My question might seem silly but when I use your code, I get the error
message, "Event not found" and it highlights " RaiseEvent DriveChanged" event
in the code . I know its coming because I have not specified thsi event in my
code. But how to specify events in my code?

Thanks
--
pmud







How to detect that NO CD exists in the CHOSEN DRIVE

by Karl E. Peterson » Sat, 03 Jun 2006 01:50:56 GMT




Well, you use the Event declaration, actually. <G> Remember, I said that
was taken from a UserControl I'd written? Up top, in that, I have this:

' Raised events.
Public Event DriveChanged(ByVal NewDrive As String)
Public Event PathChanged(ByVal NewPath As String)
Public Event FileSelected(ByVal NewFile As String)
Public Event DeviceUnavailable(ByVal InvalidDrive As String)

You're free to take that (RaiseEvent call) out, of course, if you're not
needing it.

Later... Karl
--
Working without a .NET?
http://classicvb.org/








How to detect that NO CD exists in the CHOSEN DRIVE

by cG11ZA » Sat, 03 Jun 2006 02:36:01 GMT

i Karl,

I have never used error handling before. Could you suggest some quick lins
which I can read to get how to write error handling code.

Thanks

--
pmud


"Karl E. Peterson" wrote:



How to detect that NO CD exists in the CHOSEN DRIVE

by cG11ZA » Sat, 03 Jun 2006 02:41:02 GMT

Hey Carl,

How do you come to know about error numbers?

Thanks
--
pmud








How to detect that NO CD exists in the CHOSEN DRIVE

by Karl E. Peterson » Sat, 03 Jun 2006 04:20:34 GMT




http://www.google.com/search?q=error +handling+vb
--
Working without a .NET?
http://classicvb.org/




How to detect that NO CD exists in the CHOSEN DRIVE

by Karl E. Peterson » Sat, 03 Jun 2006 04:22:33 GMT




Right-click in any code window, select Toggle, then "Break on Unhandled
Errors".

When your program throws an error, pop into the Immediate window, and type:

?err.number, err.description

Later... Karl
--
Working without a .NET?
http://classicvb.org/




How to detect that NO CD exists in the CHOSEN DRIVE

by Karl E. Peterson » Sat, 03 Jun 2006 08:24:02 GMT




Your post encouraged me to add something I wrote a long time ago to my
website. If you'd like to see how I put these three together into a single
usercontrol, please visit:

http://vb.mvps.org/samples/FileControls

Thanks... Karl
--
Working without a .NET?
http://classicvb.org/




Similar Threads

1. detecting and searching cd-rom drive

First of all, thanks to those who have helped me thus far. The
code/tutorials you've pointed me to has helped me get through my project,
however, i need something else lol

I need to know how to detect the cd-rom and extract a list of files with
their paths. This will be for music, pictures, documents, etc..im lookin on
the web for tutorials, nothing yet, maybe someone else knows a place?


2. Event to find out if a user changes a cd in the cd drive - Visual Basic/VB

3. Distingush CD Drive and CD Writer

I have created app run from CD based
To check and access CD drive i had used File System Object
I had prob now.
   When user have both cd-drive and cd-writer my application don't work properly,
   Is there any API or snippet that can distingush CD-DRIVE  and CD-WRITE

4. CD ROM Drive Letter Change & Network Drive Rename

5. Change Drive letter for CD drive in Windows XP

Hello

I have looked at scriptomatic and it shows how to retrive the drive letter 
for a CDROM drive,
But how do I set it?  Currently my drive letter is D: but I want to change 
it to Z:.
I want to use a script to do it (I want to do it on 100 different computers)

Thanks 


6. Detecting the CDROM drive and changing it to a specified drive Letter - Visual Basic/VB

7. How can I determine if a CD diskete exist in a CD drive ?

What is the code (API), to determine if a CD diskete there is
in a CD drive ?


8. cd drive access in vb.net/asp.net - .Net Framework