header image

Decimal Data Type in Visual Basic 6.0

Posted by: | September 8, 2010 | No Comment |

After I have tried to use decimal data type in visual basic 6 … I have found nothing …¬† So I tried to search help in http://msdn.microsoft.com. The result is :

If the client application uses Visual Basic 6.0 and includes the DECIMAL data type, the decimal value in Visual Basic must be defined as a Variant. If the client application uses Visual Basic .NET, the DECIMAL data type is defined directly.

The conclusion is That there is no Decimal data type in Visual Basic 6. The other option for us to cover decimal data type is using Variant data type. And of course, Variant data type will need more memory consumption. Because Variant data type covers all kind of data types, like integer, decimal, string, date, etc. To convert other data type into Decimal, we can use Cdec command. Example : Dim A as Variant, and then we assign A with a decimal value, A = Cdec(“123.45”), will result A = 123.45 (in decimal value).

In windows XP, we can use Double data type to cover decimal value (I don’t know Why ?, but it’s working). But in windows 7, there is a problem if we used Double data type. Because the decimal value in our application will be converted into non-fractional value (example : 0.3333 will be recognized as 0) … Of course, It will be a big problem if we want to calculate 1 / (1/3) … In normal situation, it will make result = 3 … but if 1/3 or 0.3333 is recognized as 0 … the operation will be like 1 / 0 … it will make an error¬† “divided by a zero”.

So … Be carefull in choosing your data type. OK ? … ^^

under: Computer Science

Leave a response

Your response: