Sunday, 2018-11-18, 1:34 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 5 - Qbasic Tutorial

So far our programs have only talked to us. Let's write one that will listen. Get rid of the previous program by clicking on File, then New on QBASIC's menu. Click on < No > when it asks if you want to save the old program now. Try this:

INPUT "Enter your name: ", Name$
PRINT "Hello, "; Name$; ". How are you today?"

Don't forget the comma (,) between "Enter your name: " and Name$. Run it. When it asks, type your name, then press the <Enter> key.

What's in a "Name$"?

"Name$" is called a "variable". To be variable means that things can change. Try running the program again, but this time type in a friend's name (don't forget the <Enter> key). Sure enough, the message changes.


INPUT Name$ takes what you type at the keyboard and puts it into the Name$ variable. PRINT Name$ prints out what is in the Name$ variable.


Variables hold letters and numbers. The dollar sign ($) means this variable can hold letters. These are called "string variables". Variables without a dollar sign can only hold numbers. We'll be seeing them soon.

You can call your variables anything you want. Try going back through this program and changing every "Name$" to "Fred$". What happens when you run it?

Another way to think of a variable is to imagine a small bucket with a name on it. Put "Name$" on it. This is the bucket's (variable's) name. Now take a piece of paper and write your name on it and drop it into the imaginary bucket. Now the variable Name$ has your name in it. Computer variables can only hold one piece of paper (one value) at a time.

PRINT and Variables

When you want to PRINT what's in a variable, leave off the double-quotation marks ("). This program will show you how this works:

INPUT "Enter your name: ", Name$
PRINT "Name$"

The first PRINT statement prints Name$ on the screen. The second PRINT statement prints whatever name you entered.


  • Variables

Category: Qbasic Tutorial | Added by: JPSor (2009-02-26) | Author: JPSor
Views: 1236 | Rating: 1.0/1 |

Qbasic Clock


Visit my Friends

Who's Online

Total online: 1
Guests: 1
Resgistered: 0

Copyright MyCorp © 2018