Finding a large variable to hold a really big number 
Author Message
 Finding a large variable to hold a really big number

Hello,

I am using the GetFreeDiskSpace API to retrieve free disk space, so I can
determine if the file I am going to copy to the drive will fit. However, I
can not find a variable large enough to hold the number of free bytes the
API returns.

Here is a portion of the code:

<start code>

Public Function GetFreeDiskSpace(FileSize, DestinationDrive) As Boolean
Dim lngTemp As Long
Dim strDrivePath As String
Dim varFreeBytes As Variant
Dim varTotalBytes As Variant

  strDrivePath = DestinationDrive

  lngTemp = GetDiskFreeSpace(strDrivePath, lngSectorsPerCluster,
lngBytesPerSector, lngNumberOfFreeClusters, lngTotalNumberOfClusters)

  varFreeBytes = CDec(lngNumberOfFreeClusters * lngSectorsPerCluster *
lngBytesPerSector)

  If varFreeBytes < FileSize Then
    GetFreeDiskSpace = False
  Else
    GetFreeDiskSpace = True
  End If

End Function

<end code>

As you can see, I have tried to convert the resulting calculation of
multiplying the free clusters by the sectors per cluster by the bytes per
sector to a decimal, but I continue to receive an over flow error when I
place it into the variant varFreeBytes. It seems I can't go any higher than
a number bigger than 2 billion.

Any help?

Jonathan



Mon, 25 Nov 2002 03:00:00 GMT  
 Finding a large variable to hold a really big number
Try using either a Single or Double data type. Check out their specs in
VB help.


Quote:
> Hello,

> I am using the GetFreeDiskSpace API to retrieve free disk space, so I
can
> determine if the file I am going to copy to the drive will fit.
However, I
> can not find a variable large enough to hold the number of free bytes
the
> API returns.

> Here is a portion of the code:

> <start code>

> Public Function GetFreeDiskSpace(FileSize, DestinationDrive) As
Boolean
> Dim lngTemp As Long
> Dim strDrivePath As String
> Dim varFreeBytes As Variant
> Dim varTotalBytes As Variant

>   strDrivePath = DestinationDrive

>   lngTemp = GetDiskFreeSpace(strDrivePath, lngSectorsPerCluster,
> lngBytesPerSector, lngNumberOfFreeClusters, lngTotalNumberOfClusters)

>   varFreeBytes = CDec(lngNumberOfFreeClusters * lngSectorsPerCluster *
> lngBytesPerSector)

>   If varFreeBytes < FileSize Then
>     GetFreeDiskSpace = False
>   Else
>     GetFreeDiskSpace = True
>   End If

> End Function

> <end code>

> As you can see, I have tried to convert the resulting calculation of
> multiplying the free clusters by the sectors per cluster by the bytes
per
> sector to a decimal, but I continue to receive an over flow error when
I
> place it into the variant varFreeBytes. It seems I can't go any higher
than
> a number bigger than 2 billion.

> Any help?

> Jonathan



Mon, 25 Nov 2002 03:00:00 GMT  
 Finding a large variable to hold a really big number
Try using a variable Dim'med as Currency. I notice that your Public Function
seems to be named the same as the API function. I would expect that VB
wouldn't like this.

Rick


Quote:
> Hello,

> I am using the GetFreeDiskSpace API to retrieve free disk space, so I can
> determine if the file I am going to copy to the drive will fit. However, I
> can not find a variable large enough to hold the number of free bytes the
> API returns.

> Here is a portion of the code:

> <start code>

> Public Function GetFreeDiskSpace(FileSize, DestinationDrive) As Boolean
> Dim lngTemp As Long
> Dim strDrivePath As String
> Dim varFreeBytes As Variant
> Dim varTotalBytes As Variant

>   strDrivePath = DestinationDrive

>   lngTemp = GetDiskFreeSpace(strDrivePath, lngSectorsPerCluster,
> lngBytesPerSector, lngNumberOfFreeClusters, lngTotalNumberOfClusters)

>   varFreeBytes = CDec(lngNumberOfFreeClusters * lngSectorsPerCluster *
> lngBytesPerSector)

>   If varFreeBytes < FileSize Then
>     GetFreeDiskSpace = False
>   Else
>     GetFreeDiskSpace = True
>   End If

> End Function

> <end code>

> As you can see, I have tried to convert the resulting calculation of
> multiplying the free clusters by the sectors per cluster by the bytes per
> sector to a decimal, but I continue to receive an over flow error when I
> place it into the variant varFreeBytes. It seems I can't go any higher
than
> a number bigger than 2 billion.

> Any help?

> Jonathan



Tue, 26 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Finding the biggest number out of 8 variables

2. Algorithm for finding biggest numbers in sequence

3. Find Largest Of 3 Numbers

4. Find Largest Of 3 Numbers

5. Inserting large number of records into a large table with SQL/DAO

6. Managing/processing a large number of large arrays

7. Need VERY large numeric variables (maybe as large as 1MB)

8. finding a variable number of substrings in a string

9. This could really be big!

10. vbrun*,dlls, and ocx really a big deal?

11. Largest Variable for the Long variable type

12. force input box and hold the variable

 

 
Powered by phpBB® Forum Software