Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

DISKSPACE(), Sys(2020), Sys(2022), Sys(2006), ISCOLOR(), Sys(17), Sys(2010)

These functions all return information about the hardware or system configuration. Several of them don’t provide accurate information.

Usage

nSpaceAvailable = DISKSPACE( [ cDrive [, nSpaceType ] ] )
cTotalSpace = SYS( 2020 )
cClusterSize = SYS( 2022 [, cDrive ])

These three functions provide information about the default disk drive. As the name implies, DISKSPACE() tells you how much room is currently available. In versions prior to VFP 7, the only parameter is cDrive, the name of the drive. VFP 7 adds another parameter, which can have the value of 1 to return the total amount of space on the drive, omit the parameter or pass 2 to return how much free space is left, and 3 to return how much free space is left for the current user. DISKSPACE() is handy when you want to copy a file to a disk and want to see if there’s enough room for it first. SYS(2020) tells you the total size of the disk and SYS(2022) returns the number of bytes per cluster. These can also be useful when figuring out what’s going to fit on a disk. There can be a maximum of 65,535 disk clusters on each volume under DOS or other FAT-based systems. On large volumes, these clusters can assume whopping sizes—16K or even 32K or larger! If you will be installing scads of dinky little files (like Visual FoxPro’s BMPs and ICOs), you may want to consider warning the operator about how much space your files could waste!

You'll want to test for reasonableness in the return values of SYS(2022), and watch for differences between the versions of VFP. Ted's CD-ROM had a perfectly acceptable 32,768 bytes per sector—as long as there was a disk in the drive. Remove the disk, and the same function under VFP 3 returns 14,988,640 bytes per sector—a bit too high to be likely! VFP 5 reported DISKSPACE() of –1 and SYS(2020) of 0, and SYS(2022) generated error 1907, "Drive specifier is invalid." VFP 6 returns similar results, with an error 1002, "Input Output failure," under Windows NT 4.

Testing this for VFP 7 opened quite a can of worms. Seems that the drive type, operating system, and even VFP's service patches all seem to play a role in what happens. When there's a disk in the CD-ROM drive, SYS(2020) returned a value of 408656384 in VFP 7 prior to SP1, and 0 with SP1.

When there's no disk in the drive, things get a little strange. Under Windows 2000, you'll get a SYS(2020) of –1, but XP raises a Windows error message dialog telling you there's no disk in the drive, and after pressing Continue, it returns –1. SYS(2022) is even flakier. It seems that, after some testing on about 10 different drives, that a CD, CD/RW, or ZIP drive raises error 1002, "Input/Output operation failure,", while a CD-DVD drive raises error 108, "File is in use by another". As with SYS(2020), Windows XP thoughtfully (not!) raises the error dialog explaining you should put a disk in the drive, and upon pressing Continue, returns "Input/Output operation failure." The number of kinds of test CD drives at Hacker Labs is limited, and we think there may be more possibilities based not only on the kind of drive, but also on the specific driver. The bottom line is that you can't count on the error messages returned for SYS(2020) and SYS(2022) in VFP 7 for removable drives.

Your best bet: Check out the DRIVETYPE() function to check for a removable drive before using this command. If you need very accurate information, you should check out the Windows API function, GetDiskFreeSpaceEx to circumvent these problems.

The parameter cDrive was introduced in VFP 5 to save us the trouble of having to SET DEFAULT TO every drive we want to test. It would have been nicer if they had added it for all the drive functions, though—SYS(2020) still reports on only the default drive. DISKSPACE() accepts the cDrive parameter as “X”, “X:” or “X:" but any other format confuses it. SYS(2022), on the other hand, ignores all characters beyond the first letter, and will happily report the cluster size of “Chihuahua” versus “Dalmatian.” Another thing that’s inconvenient is that the number displayed is so large that “?” returns scientific notation on gigabyte hard drives. Use ? TRANSFORM(DISKSPACE(“c”),”999,999,999,999”) to get a number you can view.

Example

SET DEFAULT TO A:       && A 3 1/2 drive
? SYS(2020)             && Returns "1457664"
? SYS(2022)             && Returns "512"
? DISKSPACE()           && Might return 854016.000

Usage

cGraphicsCard = SYS(2006)
lColorCapable = IsColor()

These two return information about the graphics and color capabilities of the system. They are hangovers from the DOS days when monochrome monitors and EGA cards might mean you’d need to make some changes in your displays. SYS(2006) returns the type of graphics card and monitor in use. However, it appears it can’t recognize anything more advanced than VGA in VFP 3, and just returns “Color/Color” in VFP 5 and later. ISCOLOR() returns .T. if the system is color-capable. Under Windows, we let Windows take care of most of this stuff, but we can query SYSMETRIC() for far more detailed information if necessary.

Usage

cProcessor = SYS(17)

SYS(17) returns, as a string, the processor type.

On the 32-bit versions of Windows, SYS(17) worked just fine—until the Pentium clones came along. Chips at the Pentium-class or greater all return "Pentium," even if the chip is, say, an AMD Thunderbird.

In VFP 3 under 16-bit Windows, SYS(17) on a Pentium returns "80486"—not what the client who just spent megabucks for a new machine wants to see. It's not FoxPro's fault, though—it's a Windows thing.

Usage

nFiles = SYS(2010)

This function returns 255. In FoxPro/DOS, it returns the files setting from CONFIG.SYS, but someone decided that, in Windows, you didn’t need to know. Under Windows 3.1 or later, you always have 255 file handles available.

Example

? SYS(2006)       && Might return "Color/Color"
? ISCOLOR()       && Might return .T.
? SYS(17)         && Might return "Pentium"
? SYS(2010)       && Returns 255

See Also

DriveType(), GetEnv(), Set Default, Set Display, SysMetric()