none
Question about large integer RRS feed

  • Question

  • Hi I was just playing around with the various integer formats available in vb and I came across the following issue.  When I dimension the variable I as uLong I can not seem to reach the upper limit as mentioned in the Microsoft documentation.  Here is my code:

        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim i As ULong = 18446744073709551610
            TextBox1.Text = CStr(i)
        End Sub
    

    The documentation says the upper limit is from 0 to 18,446,744,073,709,551,615 and notice I dropped the last digit down 5??

    Not that I need a number this large but was wondering what the difference is?  When I run my code I get a statement saying that i is not declared??

    Thanks Les

    Thursday, June 27, 2019 5:54 AM

Answers

  • Hi,

    add suffix UL

    Dim i As ULong = 18446744073709551615UL

    https://stackoverflow.com/questions/21841270/vb-net-ulong-overflow

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Les2011 Thursday, June 27, 2019 6:49 AM
    Thursday, June 27, 2019 6:13 AM

All replies

  • Hi,

    add suffix UL

    Dim i As ULong = 18446744073709551615UL

    https://stackoverflow.com/questions/21841270/vb-net-ulong-overflow

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Les2011 Thursday, June 27, 2019 6:49 AM
    Thursday, June 27, 2019 6:13 AM
  • Hi Alex

    What can I say but wow and how come? I thought dimensioning it as ulong it should know that right?

    If you don't mind please tell me why the UL has to be added, I never heard of that.  Also does that apply to some of the other formats?

    Thanks

    Les


    • Edited by Les2011 Thursday, June 27, 2019 6:36 AM
    Thursday, June 27, 2019 6:35 AM
  • Hi,

    You need to tell the compiler that you are working on ULong. The numeric literal defaults to an integer, so you try to use integer literals, which will cause the same overflow as your issue.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 27, 2019 6:46 AM
  • Thanks Alex for the help and education

    Les

    Thursday, June 27, 2019 6:49 AM