Sunday, 2018-11-18, 1:58 PM

Welcome Guest | RSS

Qbasic Home

Catalog categories
Qbasic Tutorial [31]

Rate my Site
Rate JPSor Site
Total of answers: 159

Main » Articles » Qbasic Tutorial

Chapter 6 - Qbasic Tutorial

Let's make that last program a little smarter. I want to be able to identify intruders playing with my programs. Wouldn't it be great if the computer could recognize someone's name and print a special message for them? How about this:

INPUT "Enter your name: ", Name$
IF Name$="Mike" THEN
PRINT "Go Away!"
PRINT "Hello, "; Name$; ". How are you today?"

You can change the Name$="Mike" to Name$="Joe", or whoever you want to go away (like a brother or sister). Run the program and type in your name (hopefully it isn't Mike). You should see the same old message as before. Now run it again and try entering "Mike" (or "Joe" or whatever you changed it to).

"Mike" Is Not The Same As "mike"

If it didn't tell the right person to go away, make sure you typed the name correctly. In QBASIC, "Mike" is not the same as "mike", so if you don't type the first letter in upper-case, the program won't work. Make sure you enter the name exactly the way you put it in the program.


The "IF..THEN..ELSE..END IF" statement in this program checks to see if Name$ has "Mike" in it. If so, then it does the PRINT statement after the "THEN". If Name$ isn't "Mike", it does the PRINT statement after the "ELSE". "END IF" tells QBASIC that the "IF" is over.


The Name$="Mike" portion of the IF...THEN is called the "condition". With numbers you can also check for "greater than" and "less than":

INPUT "Enter a number: ", Number
IF Number < 100 THEN
PRINT "Your number was less than 100"
PRINT "Your number was greater than or equal to 100"

If you want to check for "greater than", use "Number > 100". Equals works just like before, "Number = 100". Another option is "not equal" which can be done like this: "Number <> 100".

IF...THEN is one of the most powerful features of QBASIC. Using IF...THEN can make your programs very interesting. It lets your program make decisions and do something appropriate.


  • IF...THEN...ELSE

Category: Qbasic Tutorial | Added by: JPSor (2009-02-26) | Author: JPSor
Views: 1809 | Rating: 0.0/0 |

Qbasic Clock


Visit my Friends

Who's Online

Total online: 1
Guests: 1
Resgistered: 0

Copyright MyCorp © 2018