-4
Dim clicks As Integer
clicks = 0

If clicks >= 10000000000000000000 Then
    a19.ForeColor = Color.FromArgb(0, 153, 0)
End If

10000000000000000000 and above gives the error. Is there any way to have unlimited large length numbers?

Select Gamer
  • 11
  • 1
  • 10
  • Is there any sepcific reason you need to use such large numbers? It doesn't really make sense in this context. (clicking) – erikgaal Apr 19 '15 at 19:01
  • 5
    With a rate of 100 clicks per second, the 10000000000000000000 clicks will be reached after 7.6 billion years - more than half of the age of the universe! – Olivier Jacot-Descombes Apr 19 '15 at 19:02

2 Answers2

1

You can use Long instead of Integer to allow you to go up to about 9 * 10E18 (9 followed by 18 zeros). Use the L suffix on literals if they are Long

Dim bigNumber as Long = 5000000000000000000L

If you want integers that can be any size at all, look at the BigInteger Structure. For example (the following requires a reference to the System.Numerics DLL as well as the statement Imports System.Numerics

    Dim clicks As BigInteger = 0

    'Code that updates click goes here

    Dim limit As BigInteger = BigInteger.Parse("10000000000000000000")
    If clicks >= limit Then
        a19.ForeColor = Color.FromArgb(0, 153, 0)
    End If

You can also use Double to hold number as large as 1E308, but it can't hold 308 decimal digits, so the numbers will only be approximations.

Blackwood
  • 4,504
  • 16
  • 32
  • 41
  • would using BigInteger be like: Dim clicks As New BigInteger or Dim clicks As BigInteger ? – Select Gamer Apr 19 '15 at 18:58
  • It's a Structure, so `Dim clicks As BigInteger`. See the documentation I linked to. You will need to add a reference to System.Numerics. – Blackwood Apr 19 '15 at 18:59
  • So i i added this to it but there are parts underlines (errors) _ Public Structure BigInteger _ Implements IFormattable, IComparable, IComparable(Of BigInteger), _ IEquatable(Of BigInteger) End Structure – Select Gamer Apr 19 '15 at 19:06
  • I updated my answer to include a version of your original code that uses BigInteger. – Blackwood Apr 19 '15 at 19:07
  • Imports System.Numerics is wrong as it is underlined green? – Select Gamer Apr 19 '15 at 19:14
  • `Imports System.Numerics` is correct, but you must add a reference to the System.Numerics DLL. Double-click on "My Project" in Solution Explorer, and go to the "References" tab and click "Add". I should have added that BigInteger is only available in version 4 and later of the .Net Framework. – Blackwood Apr 19 '15 at 19:19
  • thanks for explaining that to me. I would have been stuck on the reference part. so now i can do Dim clicks As BigInteger = 0 ? – Select Gamer Apr 19 '15 at 19:28
  • Yes. Give it a try and it should work. However (as other commenters have pointed out), if clicks is actually a count of user clicks, it is unlikely that you need numbers this big. – Blackwood Apr 19 '15 at 19:31
  • it still shows error Overflow after changing it from Integer to BigInteger – Select Gamer Apr 19 '15 at 19:35
  • Dim clicks As BigInteger and clicks = 10000000000000000000 – Select Gamer Apr 19 '15 at 19:35
  • See the code in my answer `Dim limit As BigInteger = BigInteger.Parse("10000000000000000000")` there is no way to write a literal that is that big, so you need to use BigInteger.Parse to convert a string to a BigInteger. – Blackwood Apr 19 '15 at 19:47
  • ok cool. 1 more thing though. I am saving the value in the project settings using My.Settings. in there you can set the type to anything but is there a way to set the type to BigInteger as i have it at Integer now. – Select Gamer Apr 19 '15 at 19:57
  • 1
    I don't believe you can store a BigInteger in MySettings, which means you will have to convert the BigInteger to something else before you save it. One possibility would be to convert it to a String using the `ToString` method of BigInteger. When you want to convert the String back to a BigInteger, you can use `BigInteger.Parse`. – Blackwood Apr 19 '15 at 20:28
  • Thanks i got it to work. `Dim clicks as BigInteger` and `My.Settings.clicks = clicks.ToString` – Select Gamer Apr 20 '15 at 15:44
1

In Computer Science a number is most often represented as an integer. An integer is most often defined as a 32-bit signed integer, which means that the value can only hold up to a value from -(2^31) to (2^31)-1. To use bigger numbers, you might want to check other integer types. The most commonly used bigger integer, is the 64-bit integer, which can hold a value from -(2^63) to (2^63)-1.

erikgaal
  • 398
  • 1
  • 11