Home All Groups Group Topic Archive Search About
Author
17 Mar 2009 2:40 AM
David
I'm erring because the whole number cumulative total is greater than
the long data type.

Any suggestions on how to handle in VB?

Author
17 Mar 2009 4:04 AM
dpb
David wrote:
> I'm erring because the whole number cumulative total is greater than
> the long data type.
>
> Any suggestions on how to handle in VB?

Decimal
Currency
Double
Single

are options.  Look in online help for characteristics (and limitations)
of each.  W/o more on the problem to be solved, more specifics would be
guessing at best.

--
Author
17 Mar 2009 12:14 PM
Richard Mueller [MVP]
Show quote Hide quote
"dpb" <n***@non.net> wrote in message news:gpn7ii$pqr$1@aioe.org...
> David wrote:
>> I'm erring because the whole number cumulative total is greater than
>> the long data type.
>>
>> Any suggestions on how to handle in VB?
>
> Decimal
> Currency
> Double
> Single
>
> are options.  Look in online help for characteristics (and limitations) of
> each.  W/o more on the problem to be solved, more specifics would be
> guessing at best.
>
> --

I use currency because it is integer internally. The value displays 4
digits, but it is what is called a scaled integer divided by 10,000. The
integer overflows at 2^63-1 instead of 2^31-1. Check help for details.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Author
17 Mar 2009 12:35 PM
Rick Rothstein
> I use currency because it is integer internally. The value displays 4
> digits, but it is what is called a scaled integer divided by 10,000. The
> integer overflows at 2^63-1 instead of 2^31-1.

Actually, Currency values overflow at just over 2^49.71228762045054

--
Rick (MVP - Excel)
Author
18 Mar 2009 2:40 AM
Richard Mueller [MVP]
"Rick Rothstein" <rick.newsNO.SPAM@NO.SPAMverizon.net> wrote in message
news:Oj5XszvpJHA.996@TK2MSFTNGP03.phx.gbl...
>> I use currency because it is integer internally. The value displays 4
>> digits, but it is what is called a scaled integer divided by 10,000. The
>> integer overflows at 2^63-1 instead of 2^31-1.
>
> Actually, Currency values overflow at just over 2^49.71228762045054
>
> --
> Rick (MVP - Excel)

The maximm value should be 922,337,203,685,477.5807. Internally, this is the
integer 9,223,372,036,854,775,807 which is 2^63-1, but the value is "scaled"
by dividing by 10,000.


--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Author
18 Mar 2009 4:26 AM
Rick Rothstein
>>> I use currency because it is integer internally. The value displays 4
>>> digits, but it is what is called a scaled integer divided by 10,000. The
>>> integer overflows at 2^63-1 instead of 2^31-1.
>>
>> Actually, Currency values overflow at just over 2^49.71228762045054
>>
>> --
>> Rick (MVP - Excel)
>
> The maximm value should be 922,337,203,685,477.5807. Internally, this is
> the integer 9,223,372,036,854,775,807 which is 2^63-1, but the value is
> "scaled" by dividing by 10,000.

Ah, yes, but of course... you meant the unscaled value, not the scaled one.

--
Rick (MVP - Excel)
Author
17 Mar 2009 12:55 PM
Claus Centrino
A Long value has a maximum of 2,147,483,647.

Currency goes up to 922,337,203,477.5807 - and no one
enforces you not to have no decimals.

And if that all is not enough for you, you could create your
own huge type variable based on a class rather than a type
definition.
Author
17 Mar 2009 5:14 PM
Bee
Have a look at Variant Decimal

    Dim v As Variant

    ' not assigned
    Debug.Print VarType(v)
    Debug.Print TypeName(v)

    v = 0
    Debug.Print VarType(v)
    Debug.Print TypeName(v)

    v = CDec(0)
    Debug.Print VarType(v)
    Debug.Print TypeName(v)

    v = CDec(1000)
    Debug.Print VarType(v)
    Debug.Print TypeName(v)

    v = v + 1
    Debug.Print VarType(v)
    Debug.Print TypeName(v)


Show quoteHide quote
"David" wrote:

> I'm erring because the whole number cumulative total is greater than
> the long data type.
>
> Any suggestions on how to handle in VB?
>
>
>
Author
17 Mar 2009 10:51 PM
David
Thanks All,  I guess Currency is it.

------------------------------------

Claus Centrino

Out of "Learning"

How would you go about creating a class that could handle a type larger than
Long or Currency for that matter.

Only thing I could think of is to divided the number by some value
(say 1000 or 10000, etc) and then add them.  But how would the method return
the value since the return type would need to be defined as some type.



Show quoteHide quote
> "David" wrote:
>
>> I'm erring because the whole number cumulative total is greater than
>> the long data type.
>>
>> Any suggestions on how to handle in VB?
>>
>>
>>
Author
19 Mar 2009 5:05 PM
Claus Centrino
> How would you go about creating a class that could handle
> a type larger than
> Long or Currency for that matter.

Well, I can't you give a readily coded class (there migh
already exist one in the community, don't know) but I can
outline the steps:

Just like an integer variable consists of two bytes and  a
long variable consists of four bytes you could think about a
huge variable consisting of eight bytes.

Create a class clsHuge which holds two long public
variables, say HI and LO, which represent the high and low
part of a huge number.

Then you can say Set H = new clsHuge and assign values to
the new huge variable by H.LO = xxx, H.HI = yyy.

You can combine that in an assign method to shorten code to
"H.LetValue xxx,yyy" and for retrieving values you can have
"H.GetValue Hi, Lo".

Implementing addition and subtraction is easy, just write a
new method "Add(Hi as long, Lo as long)" and "Subtract(Hi as
long,Lo as Long)". The only thing is you must handle
overflows by your own.

If this is done you even can make it more comfortable using
methods having class memebrs as parameters, something like
"HugeVar1.AddAnotherHugeOne HugeVar2", or "HugeVar1.Clone
HugeVar2"

Implementing multiplication and division is a little bit
more difficult. But what would live be without little
difficulties :-) ? And maybe you don't need it at all if
your huge data only comes from creating subtotals.

Additionaly you'll have to build a string output function to
return the string value of HI * maxLO + LO.

Once having coded these basic functions you'll see that
working with such huge variables is almost easy, especially
as you probably don't need huge variables everywhere but
only in some special situations.

As adding and subtracting will be done by integer
calculation this won't take a long time.
Author
20 Mar 2009 3:36 PM
David
Mr Centrino:

Thanks for the input.
Will have to think on this one for a bit or byte (pun intended).
Where I have a problem with the class concept is what to
do with the return value as some point (unless I'm misunderstanding)
you would need to put your high and low values back togerher.

My thoughts are it may be easier to divide the number by some factor (say
1000, or 10000) and then deal with the number as a single or double.    This
should maintain the relationship between numbers while
keeping it within a normal defined type value.

David


Show quoteHide quote
"Claus Centrino" <c***@sofort-mail.de> wrote in message
news:gptu2e$l6q$1@online.de...
>
>> How would you go about creating a class that could handle a type larger
>> than
>> Long or Currency for that matter.
>
> Well, I can't you give a readily coded class (there migh already exist one
> in the community, don't know) but I can outline the steps:
>
> Just like an integer variable consists of two bytes and  a long variable
> consists of four bytes you could think about a huge variable consisting of
> eight bytes.
>
> Create a class clsHuge which holds two long public variables, say HI and
> LO, which represent the high and low part of a huge number.
>
> Then you can say Set H = new clsHuge and assign values to the new huge
> variable by H.LO = xxx, H.HI = yyy.
>
> You can combine that in an assign method to shorten code to "H.LetValue
> xxx,yyy" and for retrieving values you can have "H.GetValue Hi, Lo".
>
> Implementing addition and subtraction is easy, just write a new method
> "Add(Hi as long, Lo as long)" and "Subtract(Hi as long,Lo as Long)". The
> only thing is you must handle overflows by your own.
>
> If this is done you even can make it more comfortable using methods having
> class memebrs as parameters, something like "HugeVar1.AddAnotherHugeOne
> HugeVar2", or "HugeVar1.Clone HugeVar2"
>
> Implementing multiplication and division is a little bit more difficult.
> But what would live be without little difficulties :-) ? And maybe you
> don't need it at all if your huge data only comes from creating subtotals.
>
> Additionaly you'll have to build a string output function to return the
> string value of HI * maxLO + LO.
>
> Once having coded these basic functions you'll see that working with such
> huge variables is almost easy, especially as you probably don't need huge
> variables everywhere but only in some special situations.
>
> As adding and subtracting will be done by integer calculation this won't
> take a long time.
>
>
Author
20 Mar 2009 4:04 PM
Jim Mack
David wrote:
>
> My thoughts are it may be easier to divide the number by some
> factor (say 1000, or 10000) and then deal with the number as a
> single or double.    This should maintain the relationship between
> numbers while keeping it within a normal defined type value.

Certainly not as a Single, which has less precision than a Long (but
more range).

As for dividing by 10,000 -- you're describing Currency.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"
Author
21 Mar 2009 5:27 AM
James Hahn
There should be no need to do anything with the 'return' value.

By creating it as a class you have created a numeric type that you can use
like you would use any other type - increment it or do other math, compare
to other variables of the same type, display it, print it, save it to file,
etc.  The only thing is that any particular operation you use it for will
have to be created as a method or property of the class.

Rather than using two smaller numeric variables and scaling one of them, it
may be easier to use something like a byte array with one or two digits per
byte, or even as a string with one digit per character. The low level
routines can be somewhat complex, but once you have the basics in place the
higher level routines are implemented using the methods of the class.  I
know there used to be routines around for a BCD numeric class of arbitrary
size in VB, but I can't find any references now.  There's some discussion
here:
http://en.wikipedia.org/wiki/Arbitrary_precision_arithmetic

If the Java implementations are available as source, conversion is
reasonably straightforward.

Show quoteHide quote
"David" <dw85745***@earthlink.net> wrote in message
news:ugmmXGXqJHA.996@TK2MSFTNGP03.phx.gbl...
> Mr Centrino:
>
> Thanks for the input.
> Will have to think on this one for a bit or byte (pun intended).
> Where I have a problem with the class concept is what to
> do with the return value as some point (unless I'm misunderstanding)
> you would need to put your high and low values back togerher.
>
Author
21 Mar 2009 6:03 AM
Jeremiah D. Seitz
On Sat, 21 Mar 2009 16:27:40 +1100, in
microsoft.public.vb.general.discussion you wrote:

8< SNIP >8

>Rather than using two smaller numeric variables and scaling one of them, it
>may be easier to use something like a byte array with one or two digits per
>byte, or even as a string with one digit per character. The low level
>routines can be somewhat complex, but once you have the basics in place the
>higher level routines are implemented using the methods of the class.  I
>know there used to be routines around for a BCD numeric class of arbitrary
>size in VB, but I can't find any references now.  There's some discussion
>here:
>http://en.wikipedia.org/wiki/Arbitrary_precision_arithmetic

Hmmm ... a VB6 based BigNum library. Any takers? God knows I've tried,
but it was primitive, and division was a #^?@. Every level of
mathematics being based on the level prior to it, it's possible, but
the implementation gets clunky without sufficient knowledge.

Does Knuth's "Numerical recipes in C" contain any applicable formulae?

(In reviewing your response, I realized that you mentioned the
recursive nature of mathematics, but I'll leave the above paragraphs
intact for posterity <g>)

>If the Java implementations are available as source, conversion is
>reasonably straightforward.

I would expect a lot of unsigned bit-shifting, so analogous VB code
would need to be implemented, but I don't see why it couldn't be done.

    J.
    Jeremiah D. Seitz
    Omega Techware
    http://www.omegatechware.net
Author
20 Mar 2009 4:17 PM
Henning
What is wrong with the Decimal data type?
+/-79,228,162,514,264,337,593,543,950,335

/Henning

Show quoteHide quote
"David" <dw85745***@earthlink.net> skrev i meddelandet
news:OeDp8L1pJHA.5832@TK2MSFTNGP06.phx.gbl...
> Thanks All,  I guess Currency is it.
>
> ------------------------------------
>
> Claus Centrino
>
> Out of "Learning"
>
> How would you go about creating a class that could handle a type larger
> than Long or Currency for that matter.
>
> Only thing I could think of is to divided the number by some value
> (say 1000 or 10000, etc) and then add them.  But how would the method
> return the value since the return type would need to be defined as some
> type.
>
>
>
>> "David" wrote:
>>
>>> I'm erring because the whole number cumulative total is greater than
>>> the long data type.
>>>
>>> Any suggestions on how to handle in VB?
>>>
>>>
>>>
>
>
Author
20 Mar 2009 4:34 PM
Dave O.
"Henning" <computer_h***@coldmail.com> wrote in message
news:49c3c180$0$16212$57c3e1d3@news3.bahnhof.se...
> What is wrong with the Decimal data type?
> +/-79,228,162,514,264,337,593,543,950,335
>
> /Henning

Nothing, except it does not exist in VB6

Dave O.
Author
20 Mar 2009 4:45 PM
Nobody
"Dave O." <nob***@nowhere.com> wrote in message
news:%23SKgmnXqJHA.3840@TK2MSFTNGP03.phx.gbl...
>
> "Henning" <computer_h***@coldmail.com> wrote in message
> news:49c3c180$0$16212$57c3e1d3@news3.bahnhof.se...
>> What is wrong with the Decimal data type?
>> +/-79,228,162,514,264,337,593,543,950,335
>>
>> /Henning
>
> Nothing, except it does not exist in VB6

It does, but only inside a variant. See "Decimal data type" in MSDN Library.
You have to use CDec() when you first initialize it, such as with "d =
CDec(0)".
Author
20 Mar 2009 5:00 PM
Jim Mack
Dave O. wrote:
> "Henning" <computer_h***@coldmail.com> wrote in message
> news:49c3c180$0$16212$57c3e1d3@news3.bahnhof.se...
>> What is wrong with the Decimal data type?
>> +/-79,228,162,514,264,337,593,543,950,335
>>
>> /Henning
>
> Nothing, except it does not exist in VB6

Really? This doesn't work in your copy of VB6?

  Dim Big As Variant

  Big = CDec(892281625142643@)

  Big = Big + Big + Big

  Debug.Print Format$(Big, "#,#")

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"
Author
23 Mar 2009 9:46 AM
Dave O.
Sorry, I should have said "as a native data type" I avoid Variants where
ever possible as in the vast majority of cases they are not necessary. In
fact I cannot think of a single instance where I have used a Variant by
choice.

Dave O.

Show quoteHide quote
"Jim Mack" <jmack@mdxi.nospam.com> wrote in message
news:OLkCl1XqJHA.1252@TK2MSFTNGP03.phx.gbl...
> Dave O. wrote:
>> "Henning" <computer_h***@coldmail.com> wrote in message
>> news:49c3c180$0$16212$57c3e1d3@news3.bahnhof.se...
>>> What is wrong with the Decimal data type?
>>> +/-79,228,162,514,264,337,593,543,950,335
>>>
>>> /Henning
>>
>> Nothing, except it does not exist in VB6
>
> Really? This doesn't work in your copy of VB6?
>
>  Dim Big As Variant
>
>  Big = CDec(892281625142643@)
>
>  Big = Big + Big + Big
>
>  Debug.Print Format$(Big, "#,#")
>
> --
>   Jim Mack
>   Twisted tees at http://www.cafepress.com/2050inc
>   "We sew confusion"
Author
20 Mar 2009 4:28 PM
Nobody
"David" <dw85745***@earthlink.net> wrote in message
news:OeDp8L1pJHA.5832@TK2MSFTNGP06.phx.gbl...
> a type larger than Long or Currency for that matter.

Depending on the application. I would use Currency, Decimal, or Double, but
if this is not enough, check this VB6 calculator(including source) that
handles unlimited digits:

http://www.karenware.com/powertools/ptcalc.asp