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

How do I Prevent a Crash When a Letter is Typed Instead of an Integer

$
0
0
So here's the problem, I have a variable called Denary which is an integer as I need to do maths with it. If someone using my program were to type in a
letter instead of a number it would crash. I would prefer to be able to post an error message but it crashes at the console.ReadLine so my knowledge leaves me unable to solve it.

Code:

Console.WriteLine("Type a denary number between 0 and 255 to convert or press * to return to the main menu")
        Denary = Console.ReadLine 'Reads in the Denary Number

        If Denary > 0 And Denary < 255 Then
            Do While Denary > 0
                Binary(i) = Denary Mod 2
                Denary = Fix(Denary / 2) 'Divides Denary number by 2 and rounds dpwn
                i = i + 1
            Loop


Viewing all articles
Browse latest Browse all 27514

Trending Articles



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