Results 1 to 3 of 3

Thread: An incredible bug in vb6 Int function!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2021
    Posts
    193

    An incredible bug in vb6 Int function!

    I have the following code
    Code:
    Dim g As Long
    ...
    g = Int(g / 10)
    Which supposed to eliminate the last digit.
    In my case, g=39838669 and after executing this line g becomes 3983867.
    It looks like it got rounded instead of truncated!
    Furthermore, if I change the code like this:
    Code:
    Dim t As Long, g As Long
    ...
    t = Int(g / 10)
    g = Int(g / 10)
    Now t=3983867 and g=3983866!
    The second time it got it right!
    This looks like a bug in vb6 Int function, but I couldn't reproduce this bug in a new project, so something fishy is going on!
    Did anybody else encounter such inconsistency with vb6 Int function?
    Last edited by Dry Bone; Nov 28th, 2022 at 01:33 AM.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: An incredible bug in vb6 Int function!

    I can not replicate it in the IDE:
    Code:
    Option Explicit
    
    Private Sub Form_Click()
      Test1
      Test2
    End Sub
    
    Private Sub Test1()
    Dim g As Long
    
    g = 39838669
    g = Int(g / 10)
    
    Debug.Print g
    End Sub
    
    Private Sub Test2()
    Dim t As Long, g As Long
    
    g = 39838669
    
    t = Int(g / 10)
    g = Int(g / 10)
    
    Debug.Print t, g
    
    End Sub
    Code:
     3983866 
     3983866       3983866

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: An incredible bug in vb6 Int function!

    Just tested it. Cannot confirm.

    OTOH, if you want to remove the last digit, making sure no rounding whatsoever happens, use Integer division

    Code:
    Dim g As Long
        g = 39838669
        g = g \ 10
        Debug.Print g '--> returns 3983866
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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