General discussion

Locked

Custom Variable In Visual Basic 6

By Randomality ·
I need to define a custom variable in VB6, so instead of an Integer or Long, create a numerical variable that allows, say, 50 digits and 3 decimal precision. Any one know how I could manage that?
Do I need to use UDT? I dont know what that is exactly, so...
Any help would be great thanx

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Tony Hopkinson In reply to Custom Variable In Visual ...

You need more than a type, especially if you want it accurate.
Once you've decided how to represent it, you'd have to write all the operations you need for it. VB really does n't lend itself to this.
No operator overloading for instance.

Probably one of the most used methods for high accuracy is BCD (Binary Coded Decimal).
An unsigned integer in VB6 will hold 8 digits in BCD. One per each four bits. So you'd need an array of at least seven (eight would be neater).
Then you'd have to write functions for each operator you required. If you search for BCD and big numbers you'll get more tips. I did this as exercise in representaion many many years ago in pascal, once you've got the idea of BCD and come up with a strategy for storage, it's not particularly diificult if you go the long way round and remember multipication is repeated addition. Oh and you'll need to store to more than three decimal places even if that's the maximum level of precision you want if you are doing any form of division such as multiplying by a single or double. If I was doing this in VB, I'd be using a class not a type.

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums