CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2000
    Posts
    29

    subtracting two longs ??

    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



  2. #2
    Join Date
    Jan 2000
    Location
    CA
    Posts
    52

    Re: subtracting two longs ??

    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...


  3. #3
    Join Date
    Mar 2000
    Posts
    29

    Re: subtracting two longs ??

    thanks it helped


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured