SlideShare a Scribd company logo
IS NUMERIC?
Just one way we can protect the user
          from themselves!
Sometimes You want the user to
        enter only numbers . . .

Module Module1
    Sub Main()
        Dim favouriteNumber As Integer
        Console.WriteLine("What's your favourite number?")
        favouriteNumber = Console.ReadLine()

        Console.WriteLine("Your favourite number is " &
   favouriteNumber)
       Console.ReadLine()
    End Sub
End Module
Sometimes You want the user to
   enter only numbers . . .
 If I enter the number 5, the program works
Sometimes You want the user to
      enter only numbers . . .
If I enter five however, things start to break down
Sometimes You want the user to
   enter only numbers . . .

                         BUT THAT
                        STILL MAKES
                         SENSE TO
                            ME!!
Sometimes You want the user to
       enter only numbers . . .
Visual Studio is telling us there’s a InvalidCastException
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
Remember, Variables have a specific
             data type
                              Variables have a
I’m the type of                  data type
  Variable that
   holds only
 Champagne !
 Don’t you try
    and put
 Lemonade in
      me!
                  Champagne
                    Bucket
Example data types

               String
              Integer
              Double
               Float
     Champagne Char
       Bucket
              Boolean
You need to
protect the user
     from
themselves . . .
You’re gonna need
 some isNumeric
    validation
  protection . . .
!
isNumeric
We 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
isNumeric
isNumeric() will return either true or false depending
                on the input it is given
Adding isNumeric
Module Module1
    Sub Main()
        Dim favouriteNumber As Integer
        Console.WriteLine("What's your favourite number?")
        Dim temp As String
        temp = Console.ReadLine()


       While Not IsNumeric(temp)

           Console.WriteLine("YOU HAVEN'T ENTERED NUMBER!")
           temp = Console.ReadLine()
       End While

        favouriteNumber = temp
        Console.WriteLine("Your favourite number is " & favouriteNumber)
        Console.ReadLine()
    End Sub
End Module
Adding isNumeric
The user has been stopped from entering the word five
Thanks!

More Related Content

Viewers also liked

Careers In English Literature
Careers In English LiteratureCareers In English Literature
Careers In English Literature
Bill Gray Ogilvy
 
литературная карта
литературная карталитературная карта
литературная картаmukcbs55
 
Presentacion diapositivas
Presentacion diapositivasPresentacion diapositivas
Presentacion diapositivas6259874
 
Entity framework
Entity frameworkEntity framework
Entity framework
Tamer Elshahat
 
Migliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigoMigliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigoDavide Margelli
 
C 70 card_machine_brochure_2810-v2_en_original__79023 2
C 70 card_machine_brochure_2810-v2_en_original__79023 2C 70 card_machine_brochure_2810-v2_en_original__79023 2
C 70 card_machine_brochure_2810-v2_en_original__79023 2
aqeel ahmed
 
Vrste saobracaja
Vrste saobracajaVrste saobracaja
Vrste saobracaja
oslic
 

Viewers also liked (10)

Careers In English Literature
Careers In English LiteratureCareers In English Literature
Careers In English Literature
 
Hello world
Hello worldHello world
Hello world
 
литературная карта
литературная карталитературная карта
литературная карта
 
Presentacion diapositivas
Presentacion diapositivasPresentacion diapositivas
Presentacion diapositivas
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
Migliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigoMigliora l'efficienza della tua cella frigo
Migliora l'efficienza della tua cella frigo
 
C 70 card_machine_brochure_2810-v2_en_original__79023 2
C 70 card_machine_brochure_2810-v2_en_original__79023 2C 70 card_machine_brochure_2810-v2_en_original__79023 2
C 70 card_machine_brochure_2810-v2_en_original__79023 2
 
Loops
LoopsLoops
Loops
 
Vrste saobracaja
Vrste saobracajaVrste saobracaja
Vrste saobracaja
 
Flow charts
Flow chartsFlow charts
Flow charts
 

Similar to Is numeric

ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
UCLA Association of Computing Machinery
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
Python Programming
Python ProgrammingPython Programming
Python ProgrammingHumera Tariq
 
02 Primitive data types and variables
02 Primitive data types and variables02 Primitive data types and variables
02 Primitive data types and variables
maznabili
 
Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)Charling Li
 
data types in C-Sharp (C#)
data types in C-Sharp (C#)data types in C-Sharp (C#)
data types in C-Sharp (C#)
Abid Kohistani
 
Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02
A-Tech and Software Development
 
Notes1
Notes1Notes1
Notes1hccit
 

Similar to Is numeric (9)

ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
02 Primitive data types and variables
02 Primitive data types and variables02 Primitive data types and variables
02 Primitive data types and variables
 
DemoQues
DemoQuesDemoQues
DemoQues
 
Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)Coding in Disaster Relief - Worksheet (Advanced)
Coding in Disaster Relief - Worksheet (Advanced)
 
data types in C-Sharp (C#)
data types in C-Sharp (C#)data types in C-Sharp (C#)
data types in C-Sharp (C#)
 
Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02
 
Notes1
Notes1Notes1
Notes1
 

More from Peter Andrews (10)

Trimming text
Trimming textTrimming text
Trimming text
 
Splitting up text
Splitting up textSplitting up text
Splitting up text
 
Reading in files
Reading in filesReading in files
Reading in files
 
Syntax errors
Syntax errorsSyntax errors
Syntax errors
 
Arrays
ArraysArrays
Arrays
 
Rounding numbers
Rounding numbersRounding numbers
Rounding numbers
 
Select case
Select caseSelect case
Select case
 
If
IfIf
If
 
Collecting user input
Collecting user inputCollecting user input
Collecting user input
 
Variables
VariablesVariables
Variables
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 

Is numeric

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