CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    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

  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    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.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    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

  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    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

  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    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 &lt; 2.x Gigabytes. GetFreeSpace.EX and GetFreeSpaceEXAsCurrency provide support for disks &gt; 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
  •  





Click Here to Expand Forum to Full Width

Featured