Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Polling for Drives 1

Status
Not open for further replies.

derSturm

Programmer
Jul 11, 2002
1
US
What are some good ways to check for valid drives? If I want a program to be used on various and unfamiliar computers, and want to know which drives A - Z are valid, how to go about it? I know that QB 7.1 has a command to do this, but 4.5 does not.
 
I don't know how to count drives, but you don't need to check all the way to Z. Mostly valid drives are A-H, anything after that is usually a network drive
 
Ask user for them, or use only where program reside and temporary folder drives (probably, system drive - but it isn't recommended in network or industrial environments). There is no safe way to find all drives under DOS (Even commercial products like Quick Basic locks up on removed from rackmount drives or disconnected network mapping, for example).
 
Hmmm, I think I remember having this problem with a program I wrote in QB45 a few years ago. It's job was to simply gather a list of all program files on a computer... but I had a booger of a time trying to build a list of the valid drive assignments (even the ROM BIOS interrupts were of no help).

Eventually, I gave up on finding a "correct" solution and just implemented one that "worked". Naturally, this will be more likely to work for you on a Win9x system (or possibly NT - I haven't tried it).

Let a batch file do the work for you:

[tt]
QBCrLf$ = CHR$(13) + CHR$(10)
Bat$ = "@ECHO OFF" + QBCrLf$
Bat$ = Bat$ + "CTTY NUL" + QBCrLf$
FOR D = 65 TO 90
Bat$ = Bat$ + "TRUENAME " + CHR$(D) + ":>>QBDRVS.TMP" + QBCrLf$
NEXT
Bat$ = Bat$ + "CTTY CON" + QBCrLf$
ff = FREEFILE
OPEN "QBDRVS.BAT" FOR BINARY AS #ff
PUT #ff, 1, Bat$
CLOSE #ff
SHELL "QBDRVS.BAT>NUL"
ff = FREEFILE
OPEN "QBDRVS.TMP" FOR BINARY AS #ff
G$ = STRING$(LOF(ff), 32)
GET #ff, 1, G$
CLOSE #ff
KILL "QBDRVS.TMP"
KILL "QBDRVS.BAT"
FOR D = 65 TO 90
Test$ = CHR$(D) + ":"
IF INSTR(G$, Test$) > 0 THEN
DriveCount = DriveCount + 1
ELSE
EXIT FOR
END IF
NEXT
PRINT "There are"; DriveCount; "drives on this system."
PRINT "The last drive is " + CHR$(DriveCount + 64) + ":"
[/tt]


Your operating system may have a problem with the TRUENAME and CTTY directives. You might be able to replace TRUENAME with a DIR command and CTTY only redirects screen output to the NUL device so you won't see the "invalid drive assignment" message flash for any drive not available on the system (get rid of the CTTY line if you can live with this annoyance).

One minor problem with the above code is that, if A: is a valid drive assignment, it will count B: as a valid drive assignment even if there is no B: drive installed on the computer. Perhaps you can find a way around this....

Good luck. There is almost always a way to accomplish a task, though the means to the end may involve unsavory programming practices.

VCA.gif
 
I do this all of the time... Now, some of you are going to call this pretty sloppy, but it get's the job done and does it well.

I have an array called iDrives that will hold a list of the drives, then a subroutine that I can call to put the drives in the list.

Dim Shared iDrives(26) As String
GetDrives

For Looper = 1 To 26
Print iDrives(Looper)
Next

Sub GetDrives ()
CurDrive = 0
On Local Error Goto 1010
For Looper = 1 To 26
Chdrive Chr$(64 + Looper) + ":\"
CurDrive = CurDrive + 1
iDrives(CurDrive) = Chr$(64 + Looper) + ":\"
GoNext:
Next
Exit Sub
1010
If not Err = 68 Then
Chdrive Chr$(64 + Looper) + ":\"
CurDrive = CurDrive + 1
iDrives(CurDrive) = Chr$(64 + Looper) + ":\"
Endif
Resume GoNext
End Sub
 
I use this routine

FUNCTION DiskReady% (d$)
'returns: 0 if drive exists and it's ready
' 1 if drive is not ready
' 2 if drive does not exist
' 3 if drive exists and disk is an audio CD
'
'Tested in Win 95/98 and DOS 6.2
'detects RAM disks and it's supposed to detect network units
'Does not use interrupt calls!
'-----------------------------------------------------------'To use it into your programs simply copy it and add the line
' diskreadyerror: errata% = ERR: RESUME NEXT
'(without the leading ') after the END of the main program
'-----------------------------------------------------------
SHARED errata%
errata% = 0
drive$ = LEFT$(UCASE$(d$), 1) + ":"
IF drive$ = "B:" THEN
OUT &H70, &H10
IF (INP(&H71) AND 7) = 0 THEN DiskReady% = 2: EXIT FUNCTION
END IF
ON ERROR GOTO diskreadyerror
num% = FREEFILE
OPEN drive$ + "\track01.cda" FOR INPUT AS #num%
SELECT CASE errata%
CASE 53: DiskReady% = 0
CASE 71: DiskReady% = 1
CASE 76: DiskReady% = 2
CASE 0: DiskReady% = 3: CLOSE num%
CASE ELSE
PRINT "Unexpected error value "; errata%; "in Diskready function": END
END SELECT
ON ERROR GOTO 0
end function Antoni
 
Very nice. Do you know of a good place for a listing of known OUT addresses?
 
If you want to do anything meaningful with QB you almost *have* to use Call Interrupt and Call InterruptX. :)

Ralf Brown is a god in my books. PC Interrupts is always open on my desk next to my keyboard and the on-line interrupt list is always just a click away.

VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top