|
-
March 6th, 2001, 05:14 PM
#1
How do I? (2 Questions)
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
-
March 7th, 2001, 03:44 AM
#2
Re: How do I? (2 Questions)
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
[email protected]
The best way to escape a problem, is to solve it.
-
March 7th, 2001, 03:51 AM
#3
Re: How do I? (2 Questions)
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
-
March 7th, 2001, 08:54 AM
#4
Re: How do I? (2 Questions)
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
Good Luck,
-Cool Bizs
-
March 7th, 2001, 09:01 AM
#5
Re: How do I? (2 Questions) - for Q1
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
Good Luck,
-Cool Bizs
-
March 7th, 2001, 09:11 AM
#6
Re: How do I? (2 Questions)
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|