Upcoming SlideShare
×

# Is numeric

375 views

Published on

Published in: Education, Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### Is numeric

1. 1. IS NUMERIC?Just one way we can protect the user from themselves!
2. 2. Sometimes You want the user to enter only numbers . . .Module Module1 Sub Main() Dim favouriteNumber As Integer Console.WriteLine("Whats your favourite number?") favouriteNumber = Console.ReadLine() Console.WriteLine("Your favourite number is " & favouriteNumber) Console.ReadLine() End SubEnd Module
3. 3. Sometimes You want the user to enter only numbers . . . If I enter the number 5, the program works
4. 4. Sometimes You want the user to enter only numbers . . .If I enter five however, things start to break down
5. 5. Sometimes You want the user to enter only numbers . . . BUT THAT STILL MAKES SENSE TO ME!!
6. 6. Sometimes You want the user to enter only numbers . . .Visual Studio is telling us there’s a InvalidCastException
7. 7. Sometimes You want the user to enter only numbers . . .Visual Studio is telling us there’s a InvalidCastException Visual Studio is telling us that it can’t put the word five into the variable favouriteNumber
8. 8. Remember, Variables have a specific data type Variables have aI’m the type of data type Variable that holds only Champagne ! Don’t you try and put Lemonade in me! Champagne Bucket
9. 9. Example data types String Integer Double Float Champagne Char Bucket Boolean
10. 10. You need toprotect the user fromthemselves . . .
11. 11. You’re gonna need some isNumeric validation protection . . .
12. 12. !
13. 13. isNumericWe can use the isNumeric() function to tell if a number entered by the user is a number IsNumeric(temp) The variable it will check is a number
14. 14. isNumericisNumeric() will return either true or false depending on the input it is given
15. 15. Adding isNumericModule Module1 Sub Main() Dim favouriteNumber As Integer Console.WriteLine("Whats your favourite number?") Dim temp As String temp = Console.ReadLine() While Not IsNumeric(temp) Console.WriteLine("YOU HAVENT ENTERED NUMBER!") temp = Console.ReadLine() End While favouriteNumber = temp Console.WriteLine("Your favourite number is " & favouriteNumber) Console.ReadLine() End SubEnd Module
16. 16. Adding isNumericThe user has been stopped from entering the word five
17. 17. Thanks!