Viper X
March 11th, 2000, 01:12 PM
i have been trying to subtract two longs but the answer is always 0 heres what i do
dim a as long, b as long
a = timer (say: 50046.5)
b = timer (say: 50047.9) - a
vb says b = 0 when it should be a 1.4 differance. is this vb error or mine? any way to get it working? thanks for any help
JimmyT
March 11th, 2000, 02:16 PM
The most likely problem that you are encountering is that since you are defining your variables as LONG, there will be some rounding of the Timer Function (return type is a SINGLE). Timer returns the number of seconds elapsed since midnight (as a SINGLE) and when you force this into a less precise variable type (such as a LONG) you will lose fidelity. You would probably be better served to use LONG subtraction (or addition) for those cases in which the operands being manipulated are LONG or INTEGER values. For your timer, you should probably declare a as an SINGLE, and use this code
dim a as Single
dim b as Long
a = Timer
b = clng(timer - a)
I am assuming that you have some significant code that is hidden between the evaluation of a and b so that Timer will return different values.
Hope this helps...
Viper X
March 11th, 2000, 02:28 PM
thanks it helped