Solved

VB equivalent of C++ ULARGE_INTEGER type?

Posted on 1999-01-20
17
496 Views
Last Modified: 2008-03-10
The on-line MSDN has the following to say: "The ULARGE_INTEGER structure is actually a union. If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer. typedef struct ULARGE_INTEGER {ULONGLONG QuadPart;
} ULARGE_INTEGER;"

OK, fine, I can handle that. But how do I use that in VB? Is there an equivalent to this datatype in VB? Do I create my own type, and how would I use that type with API functions like GetDiskFreeSpaceEx that returns those values?

The above reference is from http://premium.microsoft.com/msdn/library/sdkdoc/winbase/largeint_44tu.htm
0
Comment
Question by:mollercw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
  • +1
17 Comments
 
LVL 3

Expert Comment

by:vikiing
ID: 1469783
The longest integer VB allows is that of 32 bits (a LONG variable). You can define your own type with something like:

Type ULONG
   ULONG_LO as LONG
   ULONG_HI as LONG
End Type

Anyway, if you have to show the value stored at a ULONG-variable, or use it for some arithmetic operation, you'll have to do some calculations (involving both parts) to get the actual value.
0
 
LVL 2

Expert Comment

by:PedroG
ID: 1469784
vikiing is rith there is no support for that in VB.

The other way that i think you can do it is to create a DLL in Vc that handles all you need, and gives the results for ex in a String (BSTR)
0
 

Author Comment

by:mollercw
ID: 1469785
vikiing mentioned creating your type much the same way as is done in VC. How would I go about using that type to get back the results, and what arithmetic will have to take place on it? Would it be possible to work with the real value when the largest VB can work with is LONG? Surely truncation will still take place if I try to display that number?
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 2

Expert Comment

by:PedroG
ID: 1469786
Yes you will never work with the real number, but with to numbers. The aritmetical operations will need to be done by you cos Vb will truncate a value to a long.

Vb supports no aritmetical operations usingn a structure!!!
0
 
LVL 15

Accepted Solution

by:
ameba earned 80 total points
ID: 1469787
I didn't try GetDiskFreeSpaceEx, but I think you can use Currency in your declaration.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1469788
>>I think you can use Currency in your declaration

Currency type has NOTHING to see (nor even close) with a 64-bit integer.
0
 
LVL 15

Expert Comment

by:ameba
ID: 1469789
Hi, vikiing
This is from VB Help:
Currency variables are stored as 64-bit (8-byte) numbers in an integer format.
Range -922,337,203,685,477.5808 to 922,337,203,685,477.5807

(Long has range -2,147,483,648 to 2,147,483,647
so it cannot be used when disk partition is >2.2GB)
0
 
LVL 2

Expert Comment

by:PedroG
ID: 1469790
i must agree with ameba, i've remember that but it is true that the currecy is a 64 bit number, but there is only one point were i don't know if it works, cos they do have a decimal part.

So they aren't integer but real numbers. The only way to find out is to try it !!
0
 
LVL 15

Expert Comment

by:ameba
ID: 1469791
If you ask me (and my income), Currency can be LESS then 'six figures' format.
0
 
LVL 2

Expert Comment

by:PedroG
ID: 1469792
LOL :)
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1469793
My apologizes to Ameba. You're right about the 64-bits representation (although the number is scaled by 10000).
0
 
LVL 15

Expert Comment

by:ameba
ID: 1469794
Thanks, vikiing
0
 

Author Comment

by:mollercw
ID: 1469795
re ameba's proposal to use Currency:

I tried it, and it worked, but not completely correctly. On my 1.6GB drive it worked fine (gave all the digits, although the last four were after the decimal point) On my 2.5GB though, it gave an answer that is incorrect by a factor of 10. The reason is that the total amount of bytes on that drive ends in a 0, so when the decimal gets hold of it, it's discarded, reducing my 2.5GB drive to a 250MB drive (in it's eyes). Unless the amount of decimals can be set, Currency is useless.

I read about the Decimal type over the weekend. Seems to be what I'm looking for, but how does one implement that seeing as VB doesn't support it yet (it's a subtype of Variant).
0
 
LVL 15

Expert Comment

by:ameba
ID: 1469796
See
http://www.mvps.org/vbnet/code/shell/diskspacefat32.htm

Or, try this code (I don't have OSR2 and all my partitions are < 2.2GB)

' add 1 combobox to form
Option Explicit
Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
   Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
   ByVal lpBuffer As String) As Long
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
   Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, _
   lpFreeBytesAvailableToCaller As Currency, _
   lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
   
Private Sub Form_Click()
   Dim r As Long
   Dim BytesFreeToCalller As Currency
   Dim TotalBytes As Currency
   Dim TotalFreeBytes As Currency
   Dim TotalBytesUsed As Currency
   Dim RootPathName As String   'the drive to find
   RootPathName = Combo1.List(Combo1.ListIndex)
   'get the drive's disk parameters
   Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
   'show the results, multiplying the returned
   'value by 10000 to adjust for the 4 decimal
   'places that the currency data type returns.  Cls  Print
   Print "  Total Number Of Bytes:", _
      Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
   Print "  Total Free Bytes:", _
      Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
   Print "  Free Bytes Available:", _
      Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
   Print "  Total Space Used :", _
      Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
End Sub

Private Sub Form_Load()
    On Error Resume Next
   Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
   LoadAvailableDrives Combo1
   Combo1.ListIndex = 1
   Caption = "select drive and click on form"
End Sub

Private Function rgbGetLogicalDriveStrings() As String
   'returns a single string of available drive
   'letters, each separated by a chr$(0) null 'and terminated with two nulls
   Dim r As Long
   Dim sBuffer As String
   sBuffer = Space$(64)
   Call GetLogicalDriveStrings(Len(sBuffer), sBuffer)
   'need the two terminating chr$(0)'s,  'so just trim the trailing spaces
   sBuffer = Trim$(sBuffer)
   rgbGetLogicalDriveStrings = sBuffer
End Function

Private Sub LoadAvailableDrives(cmbo As ComboBox)
   Dim r As Long
   Dim DriveSize As Long
   Dim lpBuffer As String
   Dim currDrive As String
   'get the list of all available drives
   lpBuffer = rgbGetLogicalDriveStrings()
   'Separate the drive strings and add them 'to the combobox.
   Do Until lpBuffer = Chr(0)     'strip off one drive item from the lpBuffer
      currDrive = StripNulls(lpBuffer)     'add the drive to the combo list
      cmbo.AddItem currDrive
   Loop
End Sub

Private Function StripNulls(startStrg As String) As String
   'Take a string separated by a space, and split off 1 item, and
   'shorten the string so that the next item is ready for removal.
   Dim c As Long
   Dim item As String
   c = 1
   Do
      If Mid(startStrg, c, 1) = Chr(0) Then
         item = Mid(startStrg, 1, c - 1)
         startStrg = Mid(startStrg, c + 1, Len(startStrg))
         StripNulls = item
         Exit Function
      End If
      c = c + 1
   Loop
End Function


0
 
LVL 15

Expert Comment

by:ameba
ID: 1469797
Corr.
In Form_Click line 12:  Cls and Print should go to next line
   Cls
   Print
0
 

Author Comment

by:mollercw
ID: 1469798
ok kewl ... i'll go look at that code at home tonight ... seems to me that just multiplying the value by 10000 is not going to solve the problem that a drivesize might end in a zero as one of mine does (ie. 2*10^8 = 200,000,000 = 20000.0000 when represented by Currency)
0
 

Author Comment

by:mollercw
ID: 1469799
thx ameba =)

i used that code and it works perfectly :) the little bit of arithmetic i do on it (changing values from bytes to megabytes) also works as it should :)

thx a mil :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question