Select Case Statements is basically just a way of isolating different possibilities for a variable value.
Example 1:
DIM Keypressed AS STRING
CLS
PRINT
INPUT “Enter a key (A,B,C,D): “, Keypressed
PRINT
SELECT CASE Keypressed
CASE ”A”
PRINT “A Was Entered”
CASE “B”
PRINT “B Was Entered”
CASE “C”
PRINT “C Was Entered”
CASE “D”
PRINT “D Was Entered”
CASE ELSE
PRINT “Another Key Was Entered”
END SELECT
OUTPUT:
When you click on either A,B,C or D the result you get is that the Key you choose was Entered, but of another key (Assuming E or H) the result you get will be “Another Key Was Entered”
Example 2: Program to Check Score and also Grade Them.
DIM Firstname AS STRING
DIM LastName AS STRING
DIM Score AS INTEGER
CLS
PRINT
INPUT "Enter FirstName: ", Firstname
INPUT "Enter LastName: ", LastName
PRINT
PRINT "Welcome to Score Checker, "; Firstname; " "; LastName
PRINT
INPUT "Enter the Grade: ", Score
PRINT
SELECT CASE Score
CASE IS >= 90
PRINT "Grade A+"
CASE 85 TO 89
PRINT "Grade A"
CASE 80 TO 84
PRINT "Grade B+"
CASE 75 TO 79
PRINT "Grade B"
CASE 70 TO 74
PRINT "Grade C+"
CASE 65 TO 69
PRINT "Grade C"
CASE 60 TO 64
PRINT "Grade D+"
CASE 55 TO 59
PRINT "Grade D"
CASE 0 >= 54
PRINT "Fail"
END SELECT
OUTPUT:
Follow @Elitcode On Twitter
while executing Program to Check Score and also Grade Them, i got syntax error "Parse failed: Syntax error at 21:16: Token(89)"
ReplyDeletePlease check