GCSE Computing CASE Statements Park House School Copyright

  • Slides: 4
Download presentation
GCSE Computing: : CASE Statements Park House School © Copyright (P. Marshman 2010) All

GCSE Computing: : CASE Statements Park House School © Copyright (P. Marshman 2010) All Rights Reserved

Case Statements: Why we need them n Case statements should be used where you

Case Statements: Why we need them n Case statements should be used where you would normally use a number of IF statements; n These tidy up your code without the need to insert End Ifs throughout your coding structure; n The following would be good reasons for using a Case Statement: n The user is asked a question and you wish to carry out an action n n For example you can type in a type of animal and the program will reply with an example creature; The user is asked to select from a menu n For example the user is asked what application they wish to run from a list, depending on the choice, the correct program will load; [Poor cartographer booklet] Park House School © Copyright (P. Marshman 2010) All Rights Reserved

Case Statements: In practice n The following code asks the user to enter a

Case Statements: In practice n The following code asks the user to enter a type of animal, the program will reply with an example: Dim s. Animal. Type as String s. Animal. Type = Inputbox (“Please enter an animal type”) Select Case s. Animal. Type Case “Mammal” Msgbox “Elephant” Case “Amphibian” Msgbox “Frog” Case “Fish” Msgbox “Shark” End Select [Poor cartographer booklet] Park House School © Copyright (P. Marshman 2010) All Rights Reserved

Case Statements: In practice n The following code asks the user to enter which

Case Statements: In practice n The following code asks the user to enter which program they wish to load: Dim i. Response as Integer s. Animal. Type = Inputbox (“Please enter which program you wish to load”) Select Case i. Response Case 1 load_word() Case 2 load_excel() Case 3 load_powerpoint() End Select [Poor cartographer booklet] Park House School © Copyright (P. Marshman 2010) All Rights Reserved