BBS: Inland Empire Archive
Date: 03-26-93 (09:24)             Number: 309
From: DOUGLAS LUSHER               Refer#: NONE
  To: ROBERT CHURCH                 Recvd: NO  
Subj: DISK NOT READY, AND GENER      Conf: (2) Quik_Bas
RC>How can I detect these before they happen?  Here's the scenario.
RC>I call FindFirst.  Remember this is on a floppy drive.  If the disk isn't
RC>there the system locks up!  I don't wan't to use error trapping if I can
RC>help it.  What can I do?  BTW, the FindFirst routine sets an error flag if
RC>an error occured (DOSError%).

You can use the function below to determine if there is a disk in
a floppy drive. It returns True (-1) if the specified floppy drive is
has a disk in it and is ready to go. Be sure to load QB with the /L
switch. Then use the function as follows:

D$ = "A:"
IF FloppyDriveReady(D$) THEN
  'do whatever you want on the drive, there's a disk in it
  'no disk is present in the drive, or there is some other
  'problem with it.

FUNCTION FloppyDriveReady% (Drive$)
DIM Register as RegType

Drive% = (ASC(Drive$) OR 32) - 97

'reset floppy drive
Register.AX = 0
Register.DX = Drive%
CALL Interrupt(&H13, Register, Register)

Register.AX = &H401
Register.CX = &H101
Register.DX = Drive%
CALL Interrupt(&H13, Register, Register)
'call the interrupt twice since if a disk has just been inserted,
'the first time gives a wrong answer
Register.AX = &H401
Register.CX = &H101
Register.DX = Drive%
CALL Interrupt(&H13, Register, Register)

FloppyDriveReady% = ((Register.Flags AND 1) = 0)


By the way, if you're doing a lot of work on floppy drives, you might
also want to check if the disk in the drive is write-protected or not.
I have code for that also, if you need it. The function above tests only
that a disk is present. If you try to write to a protected disk, you'll
still get an error.

  SLMR 2.1a  I love it when a plan comes together.

--- TMail v1.30.4
 * Origin: TC-AMS MLTBBS 2.2 - Minnetonka, MN (612)-938-4799 (1:282/7)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET