Click to See Complete Forum and Search --> : How do I? (2 Questions)


John G Duffy
March 6th, 2001, 04:14 PM
How do I

1). Determine the Cluster size of the media on a disk drive?
2). Determine if a Dynamic array has any elements.
Example:

Dim MyArray()
'
x = Ubound(MyArray) ' this will cause an error



'
I have tried IsNull, IsEmpty, Nothing, Null, etc but to no avail.
I hate to depend on error processing to find out. There must be a pleasant way to do this.

John G

Cakkie
March 7th, 2001, 02:44 AM
Question 1:
dunno

Question 2:
You can call the element, and watch for errors, like this:

on error resume next ' ignore errors
Err.Clear ' clear previous errors (if any)
x = Ubound(myArray)
on error Goto 0 ' no longer ignoring errors

If Err.Number <> 0 then
' no elements
else
' at least 1 element
End If





Tom Cannaerts
slisse@planetinternet.be

The best way to escape a problem, is to solve it.

Clearcode
March 7th, 2001, 02:51 AM
Q2:
No the "on error resume" method is the only way I have found to test arrays which is why they are unsafe.
I have taken to always using objects of type "Collection" instead and have written this requirement into my co. VB coding standards.

HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

coolbiz
March 7th, 2001, 07:54 AM
Another option is to have another function to check for the upperbound of the array:

function AnyElement(myArray() as string) as Boolean
on error trap_err
call ubound(myArray)
AnyElement = true
exit function

trap_err:
AnyElement = false
end function



Good luck.

-Cool Bizs

coolbiz
March 7th, 2001, 08:01 AM
Forgot about the Q#1. Hmm... well you have to resort to using APIs. Few functions that you can check out: GetDiskFreeSpaceEx() or a combination of CreateFile() and DeviceIoControl() functions.

I've written a little COM DLL that gets the size of the disk (total and free space). Email me if you wanna check it out.

-Cool Bizs

John G Duffy
March 7th, 2001, 08:11 AM
Thanks to all of you that responded to my plea. On Question #1 (Disk CLuster size) - GetDiskFreeSpace does give Cluster Size but is limited to disks < 2.x Gigabytes. GetFreeSpace.EX and GetFreeSpaceEXAsCurrency provide support for disks > 2.0 Gig but does not include the Cluster size.
The GetDiskFreeSize does appear to work correctly for Clusters. Just the Space reporting is incorrect. I may just look into IODEVICECONTROl as per one of the suggestions.

Again, Thanks

John G