Tuesday, 2024-05-07, 4:23 AM

Welcome Guest | RSS

MainRegistrationLogin
Qbasic Home

Catalog categories
Qbasic Tutorial [31]

Rate my Site
Rate JPSor Site
Total of answers: 168

Main » Articles » Qbasic Tutorial

Chapter 9 - Qbasic Tutorial

IF...THEN...ELSE is fine if you only have two things you want to check. What if you have 5 or 6 friends that might use your computer and you want the computer to say something different to each of them? Try this:

 CLS
INPUT "Enter your name: ", Name$
SELECT CASE Name$
CASE "Ted"
PRINT "Greetings, oh powerful master"
CASE "Mike"
PRINT "Go away!"
CASE ELSE
PRINT "Hello, "; Name$; ". How are you?"
END SELECT

Whew, that was a big one. Fortunately we learned how to save in Chapter 8. Save it if you want before running it. Feel free to change "Ted" and "Mike" to "Laura" and "Robin" or whoever.

SELECT CASE

SELECT CASE first checks Name$ for the value "Ted". If it finds it, it does the PRINT after the CASE "Ted". When the PRINT is done, it skips over the rest of the CASEs. It keeps checking against each CASE until it gets to CASE ELSE. If it hasn't found anything, it will do whatever is after the CASE ELSE.

Just In CASE

SELECT CASE can also be used with numbers as well as strings. Here's a quick example:

 CLS
INPUT "Enter a number: ", Number
SELECT CASE Number
CASE 1234
PRINT "Thank you for entering the secret number 1234"
CASE 22
PRINT "Well, 22 is an interesting number"
CASE ELSE
PRINT "You must not know the secret number"
END SELECT

Learned

  • SELECT CASE


Source: http://jpsor.ucoz.com
Category: Qbasic Tutorial | Added by: JPSor (2009-02-26) | Author: JPSor
Views: 1931 | Rating: 0.0/0 |
Login

Qbasic Clock

Search

Visit my Friends

Who's Online

Total online: 1
Guests: 1
Resgistered: 0


Copyright MyCorp © 2024