Bug? Unexpected result of initialising a Long value

Brian Dean

Well-Known Member
Licensed User
Longtime User
B4X:
    Dim day1 As Long = 20193
    day1 = day1 * 24 * 3600 * 1000
    Log(DateTime.Date(day1))            ' Shows 04/15/2025
    Dim day2 As Long = 20193 * 24 * 3600 * 1000
    Log(DateTime.Date(day2))            ' Shows 01/11/1970

This might be a well-known behaviour but it took me a while to discover.
 

Cableguy

Expert
Licensed User
Longtime User
In the first run, only day1 is long, and then you multiply them by INTs, on the second, you are defining the resulting operation of INTs as Long.... different things, give different results.
I would say it's a BUG, but ratter a "be careful with your definitions" heads up!
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I am guessing that when you initialise a Long "in situ" it is initialised as an Int. Maybe there is a reason but it seems unexpected behaviour to me.
 
Top