SlideShare a Scribd company logo
1 of 17
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 LiteratureBill Gray Ogilvy
 
литературная карта
литературная карталитературная карта
литературная картаmukcbs55
 
Presentacion diapositivas
Presentacion diapositivasPresentacion diapositivas
Presentacion diapositivas6259874
 
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 2aqeel ahmed
 
Vrste saobracaja
Vrste saobracajaVrste saobracaja
Vrste saobracajaoslic
 

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

02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and VariablesIntro 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 variablesmaznabili
 
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
 
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

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

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