BBS: Inland Empire Archive Date: 09-22-93 (18:51) Number: 46 From: ANDY THOMAS Refer#: NONE To: GARY BLYDENBURGH Recvd: NO Subj: Drive space Conf: (2) Quik_Bas
GB> Under OS/2 I get negative numbers under DOS it works fine.
Oh, I didn't realize that was the "problem" you were having.
In that case, you're doing everything right!
Your math is just getting confused because of the way QB stores
integers. The following code gets the drive space and includes
corrections to avoid the negative numbers (up to 2
gigabytes)....
'>>> Page 1 of DRIVE.BAS begins here. TYPE:BAS
TYPE regtype
Ax AS INTEGER
Bx AS INTEGER
Cx AS INTEGER
dx AS INTEGER
bp AS INTEGER
si AS INTEGER
di AS INTEGER
flags AS INTEGER
DS AS INTEGER
es AS INTEGER
END TYPE
DIM SHARED Inreg AS regtype, Outreg AS regtype
CLS
DEFINT A-Z
Use$ = "#########"
Drive$ = "C"
Drive% = ASC(UCASE$(Drive$)) - 64
Inreg.Ax = &H3600
Inreg.dx = Drive%
CALL interrupt(&H21, Inreg, Outreg)
IF NOT (Outreg.Ax AND &HFFFF) THEN
SectorsPerCluster& = Outreg.Ax
BytesPerSector& = Outreg.Cx
' The following computations are necessary to
' transform signed integers to positive long
' integers. DX and BX will usually be greater
' than the maximum positive integer of 32767.
TotalClusters&=((((Outreg.dx AND &HFF00) / 256) AND &HFF) *_
256&) + (Outreg.dx AND &HFF)
FreeClusters&=((((Outreg.Bx AND &HFF00) / 256) AND &HFF) *_
256&) + (Outreg.Bx AND &HFF)
TotalCapacity& = TotalClusters& * SectorsPerCluster& *_
BytesPerSector&
FreeCapacity& = FreeClusters& * SectorsPerCluster& *_
BytesPerSector&
PRINT "Drive:"; Drive$
PRINT "Sectors/Cluster:"; SectorsPerCluster&
PRINT "Bytes/Sector:"; BytesPerSector&
PRINT "Total number of clusters:"; TotalClusters&
PRINT USING Use$; "Total drive capacity:"; TotalCapacity&
PRINT USING Use$; " Free drive capacity:"; FreeCapacity&
' Note: due to the use of long signed integers this
' program will report a negative drive capacity for
' drives over 2 gigabytes.
ELSE
PRINT "Error - drive invalid"
END IF
'>>> Page 1 of DRIVE.BASends here. Last page.
Write back if you've got any questions....
-Andy In San Francisco, CA on 09/22/93 @ 18:56
* RM 1.2 00593 * Cat philosophy: When in doubt, cop an attitude.
$$
--- Squish v1.01
* Origin: Coconino County *415-861-8290* San Francisco, CA (1:125/28)

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