Hi all,
How can i check whether disk is in floppy drive?
Thanks
Printable View
Hi all,
How can i check whether disk is in floppy drive?
Thanks
The easiest way is to try to read it an trap its error.
Thats a great idea..............:)Quote:
Originally posted by Mc Brain
The easiest way is to try to read it an trap its error.
For example:VB Code:
Option Explicit Public Function IsDriveReady(Drive As String) As Boolean Dim cDir As String On Error GoTo NotReady IsDriveReady = True If Len(Drive) = 1 Then Drive = Drive & ":" 'Save the current dir cDir = CurDir 'Change the current dir to the drive we want to test ChDir Drive 'Change back to the path we were before ChDir cDir On Error GoTo 0 Exit Function NotReady: If Err = 75 Then 'Path/File access error IsDriveReady = False Resume Next End If End Function Private Sub Form_Load() MsgBox IsDriveReady("A") 'or MsgBox IsDriveReady("A:") End Sub
How much of that code is really needed?Quote:
Originally Posted by Mc Brain
Somthing like that?Quote:
Originally Posted by Mc Brain
You still need to read the disk.
Dir(Drive) would do it.
Two things:Quote:
Originally Posted by the_inferno
a) I did not post the second snippet. I don't know why it says I originally posted.
b) You stripped out all the lines which actually "checks" if the drive is ready.
Lol, damn!Quote:
Originally Posted by Mc Brain
So how much do I really need?
Could be...Quote:
Originally Posted by the_inferno
VB Code:
Public Function IsDriveReady(Drive As String) As Boolean Dim cDir As String On Error GoTo NotReady IsDriveReady = True If Len(Drive) = 1 Then Drive = Drive & ":" cDir = Dir(Drive) On Error GoTo 0 Exit Function NotReady: If Err.Number = 75 Then 'Path/File access error IsDriveReady = False Resume Next ElseIf Err.Number = 52 Then 'Bad file name or number IsDriveReady = False Resume Next End If End Function Private Sub Form_Load() MsgBox IsDriveReady("A") 'or MsgBox IsDriveReady("A:") End Sub