Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27351

VS 2012 Need to identify and reject decimal numbers when input by user

$
0
0
I am creating a very basic program, which relies upon the user inputting a number (variable) which I have declared as an integer. Because it is an integer the number input needs to be a whole number, and therefore I need to reject decimal numbers with an error message. I thought this would be quite simple. I envisaged the following code would be sufficient:

Code:

ElseIf n <> Int(n) Then
            Console.WriteLine("Data invalid. Please enter a whole number.")

Unfortunately it's just continuing with the program. Using a breakpoint I have discovered that even if the variable n in put by the user is 4.6 then the value of n just changes to 5 and therefore n is equal to Int(n)!

I can't see why this doesn't work. Any help or advice would be greatly appreciated.

Viewing all articles
Browse latest Browse all 27351

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>