QB ON ACID ISSUE #4 December 21st, 1999 _________________________________________________________________ Beginner's Tutorials: Chapter 1 - Beginning Commands This is a set of tutorials that will come out 1 each issue of QBoA. They are aimed to teach you how to use QB from the beginning. I will assume you have QBasic and know your way around it. Today we will talk about the commands PRINT, CLS, and INPUT. I will also introduce you to variables. ______________________________________________________________________ PRINT The PRINT command does what it says, it PRINTs. What does it PRINT to you ask? Not the printer, but the screen. It simply PRINTs the words you specify to the screen. The syntax for PRINT is PRINT "". Put what you want to show up on the screen inside the quotes. PRINT "Hello World!" Example Code CLS What happens when you write a program, run it, then add some more code to it and run it again? You still see what was on the screen the last time you ran it. To fix this problem put the command CLS in your program. CLS stands for CLear Screen. It does what it stands for, it clears the entire screen. The syntax for this is, of course, CLS. VARIABLES Variables are used to store information in your computers memory. Think of them as storage boxes in your computer. Variables are VERY useful. They are almost ALWAYS used in a program. There are five different types of variables. They are string, integer, long integer, single precision, and double precision. Different symbols must be placed at the end of variable names so QB knows what type of variable it is working with. Strings use $, integers use %, long integers use &, single precision uses !, and double precision uses #. The type of variables you will use most often are strings and integers. Strings store words, integers store numbers. To declare a variable just do this: ExampleVariable$ = "hello". That is a string variable(notice the $) that is now storing the word "hello". When declaring a string variable make sure to put its value inside quotes. To declare an integer variable just do this: IntegerVariable = 8. Notice that I didn't have a % at the end of the variable name. That's because with integers you don't have to have one. If you don't put a symbol at the end of the variable name, QB makes it integer by default. name$ = "Bob" score% = "1500" age = "15" Example Code INPUT Programs are no good if you can't accept input from the user, right? Well that is what this command does. Judging by its name, you probably knew that already. The syntax for INPUT is this: INPUT; "What is your name" (, or ;) variable. Lets break this down. First, you have the command. Next is a semicolon, which is optional. The semicolon right after INPUT keeps the cursor on the same line after the user presses enter. Next is prompt string. It is what shows up when the INPUT code executes. Next is either a comma or a semicolon. If you put a semicolon then a question mark appears after the prompt string. If you put a comma, then no question mark appears. Last is the variable you want to store the users input in. Now, about the Prompt String, some might not understand it, so I will talk about it. If your prompt string is "What is your name" then the words "What is your name" will appear on the screen and the program will wait for the user to input the answer. INPUT "Hello. What is your name"; usersname$ INPUT "Enter your Zip Code: ", zipcode INPUT; "Enter your age: ", age Example Code PRINTING VARIABLES So, you used the input command and stored some data from the user in a variable, but what good is the data if you can't display it? Well you can using the PRINT command. It's VERY simple, heres the syntax: PRINT variable. You just type PRINT then the variable name, easy stuff. Don't forget to include the variable type symbol. PRINT playername$ PRINT age PRINT score% PRINT enemyname$ Example Code YOUR HOMEWORK Your homework is to make a program that clears the screen, asks the user for his/her name, stores it in a variable, and prints out put his/her name on the screen. See you next issue! Written By: Nova - brandon@nssoft.cjb.net