I just hit an interesting error in VB6 today.
I was trying to calculate a distance between two points. No problem there except I didn’t want to put something on a page that said “48.723569″ miles. That would look dumb.
No problem, I thought, I’ll format the output using VB’s format command, giving the number string as “#####0.0″.
But for certain numbers, format kept giving me the answer 0.0
No problem, I’ll use Round instead.
Same error. Some calculations worked, others got rounded to zero regardless…
Debugging showed that the number was too long to display properly (pi is involved in the calculation, so in theory the number goes on forever).
Instead VB’s debug window displayed the start of the number but ended it in “E-02″
Which is was what confusing Format and Round.
My working (but probably not elegant) solution was to cstr the number, remove the E-02 part and then carry on:
SortedDistance = CStr(myDistance)
SortedDistance = Replace(SortedDistance, “E-02″, “”)
Two simple lines that got rid of the headache.