Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent 64-bit integer in VB6?

Tags:

vb6

I am having to augment a legacy app to handle 64-bit integers. However, VB6 doesn't have a data type for that. The recommendation online that I've found has been to use the Currency data type.

However, I've found that I am running into some overflow issues.

Example - Results in Overflow during CCur call:

dim c as currency

' set maximum value of int64
c = CCur("9223372036854775807")

However, if I apply a smaller number (but still much larger than int32), it does work:

dim c as currency

' Remove the last 4 digits
c = CCur("922337203685477")

So what am I missing here? How can I handle a 64-bit value?

The only thing that I need to do with the 64-bit values is to read them from a SQL Server stored procedure (it comes as sql type bigint) and then display it to the form.

like image 698
AngryHacker Avatar asked Nov 07 '16 22:11

AngryHacker


2 Answers

ADO Field.Value is type Variant. When you retrieve an adBigInt in VB6 the Variant will be of subtype Decimal.

like image 61
Bob77 Avatar answered Sep 17 '22 23:09

Bob77


You can use Variant datatype with CDec() conversion.

dim c as variant

' set maximum value of int64
c = CDec("9223372036854775807")

Now you can even use standard vb6 math operations, or string conversion functions on c.

Dim c As Variant, d As Variant

c = CDec("9223372036854775807")

Dim i As Integer

i = 1000
d = 10

Debug.Print c + i
Debug.Print c / d
Debug.Print CStr(c)

Results

 9223372036854776807 
 922337203685477580,7 
9223372036854775807

Just be aware that Decimal type Variant is wider than 64 bits, so you don't get the 'Overflow' on the server side :)

like image 45
Milan Oparnica Avatar answered Sep 21 '22 23:09

Milan Oparnica