I have come across what (may be) a bug in VB. Can anyone shed some light on
what they think could be going on?
Compare the following three loops and the results
Dim c As Currency
For c = 0@ To 5670000@ Step 5.67@
Next
MsgBox c
'5670005.67
For c = 0@ To 113400000@ Step 567@
Next
MsgBox c
'113400567
For c = 0@ To 1134000@ Step 5.67@
Next
MsgBox c
'858993.66 ???
Matthew
Don't worry - MS has got back to me and confirmed it as a bug. Pretty scary
in my books.
Matthew
Matthew Wills <Te...@test.com.au> wrote in article
<01be69e4$0ad5db40$149e53a0@ws020227>...
Matthew Wills wrote in message <01be69f8$b8ebf570$149e53a0@ws020227>...
Comments inline.
Matthew
In article <Oc0pFTka#GA.128@upnetnews03>,
"Neila Nessa" <neila...@msn.com> wrote:
> Matthew,
> That is *VERY* scary. I replicated it on VB6. A workaround is to change the
> Currency to a Double.
Not a very good workaround - doubles have problems of their own (being fp).
> How did you happen to discover this one? Any ideas as to where it might
> creap into play and
> destroy the fabric of civil-lies-ation?
I was doing some unit testing of my number to words algorithm when I stumbled
onto it.
The MS guy said the following:
<Start>
This is certainly a fairly convincing bug!
A bit more playing around with it reveals that the for/next loop's comparison
will fail if the 32nd bit of the number is set. A currency is represented
internally as a large integer (64 bits), and the decimal point is
left-shifted four places. If the comparison number has the bit equivalent to
214748.3648 set (the 32nd bit), then the comparison will fail. (It basically
forgets about this bit)
This will only occur with for/next loops, and will only be present in the
environment, or in p-code executables.
I will bug this immediately. If you wish to pursue a hotfix please let me
know. <End>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
> For c = 0@ To 1134000@ Step 5.67@
> Next
> MsgBox c
> '858993.66 ???
I got the same behavior in VB4-32 and Access '97 VBA, but not in VB3 or
VB4-16. (I don't have VB5, 6, or Office '95 on my poor overloaded Libretto)
Didn't MS just come out with VS 6.0 Service Pack 2 already? Sheesh!
--
Joe Foster <mailto:jfo...@ricochet.net> Space Cooties! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!