I'll setup the background to my problem first, as it might explain my problem. We've been using a device to store a serial number of another device in it's memory. This has worked fine with numerical serial numbers, because the data type is double. However, the new equipment has serial numbers containing both alpha and numerical data.
So my first thought was to somehow convert these new serial numbers into a sort of code number which I could store as DOUBLE. My method to do this was to grab the ascii code of each letter / number as 3 digits, and just create a number containing all these digits. For example, if the code was Alf, the number would be 065108102. I found I kept loosing the zero, so I started my number with 999.
Now my problem with this is as follows. In Visual Basic 6, the help file has the following description for the DOUBLE data type :
So this should manage a short serial number. However, even with a number as short as "999097098099100101102" I get some kind of conversion error, where the string converted to DOUBLE becomes "999097098099100000000". I really don't understand why.
My test code is below :
Dim TestNoString As String
Dim TestNoDbl As Double
TestNoString = "999097098099100101102"
TestNoDbl = CDbl(TestNoString)
Debug.Print TestNoDbl
Debug.Print Format(TestNoDbl, "000000000000000000000")
Debug.Print TestNoString
So why is this not working? And is there a better way of converting and storing a serial number such as "A12345bcde4" as double?
So my first thought was to somehow convert these new serial numbers into a sort of code number which I could store as DOUBLE. My method to do this was to grab the ascii code of each letter / number as 3 digits, and just create a number containing all these digits. For example, if the code was Alf, the number would be 065108102. I found I kept loosing the zero, so I started my number with 999.
Now my problem with this is as follows. In Visual Basic 6, the help file has the following description for the DOUBLE data type :
A double-precision floating-point value with a range of –*1.79769313486232E308 to *–*4.94065645841247E-324 for negative values, 4.94065645841247E-324 to 1.79769313486232E308 for positive values, and 0.
So this should manage a short serial number. However, even with a number as short as "999097098099100101102" I get some kind of conversion error, where the string converted to DOUBLE becomes "999097098099100000000". I really don't understand why.
My test code is below :
Dim TestNoString As String
Dim TestNoDbl As Double
TestNoString = "999097098099100101102"
TestNoDbl = CDbl(TestNoString)
Debug.Print TestNoDbl
Debug.Print Format(TestNoDbl, "000000000000000000000")
Debug.Print TestNoString
So why is this not working? And is there a better way of converting and storing a serial number such as "A12345bcde4" as double?