Hello again for my second tutorial. This tutorial assumes that you already know about CLS and PRINT. If you don't then read my fist tutorial. This tutorial focuses on some harder stuff like variables and commands, like INPUT, LET. Lets get down to business... VARIABLES --------- Those of you with knowledge of algebra, science, etc will know what a variable is. A variable is a symbol(s) that holds a value, this could be numerical or text. In Qbasic a variable is asigned a value to hold, this value can be anything. You can tell what kind of thing a variable has from a symbol added on to the end. For the moment we will look at two of them the % (percent) sign and the $ (Doller) sign. In QBasic they mean different things. The % means an integer and the $ means string (text). variables don't have to have a sign on the end, these usually have a numerical value. LET --- A new command, LET this command is very useful it can assign a value to a variable: '-------------------- LET A$ = "HELLO" LET B$ = "WORLD." '-------------------- This short program will assign the memory space 'A$' with the value of 'HELLO' and the space 'B$' with the value 'WORLD.' This is all fine and well but they're not much use to us like this. We need to call back a command, previously taught in the first tutorial. The PRINT command. Now, we know that PRINT can write words and numbers on the screen provided that they are typed with the syntax (a syntax is how a command is set out e.g. PRINT [words]) but it can also be used to print variables. This is obvious when you think about it! Have a look at the followIng program: '-------------------- CLS LET A$ = "HELLO " LET B$ = "WORLD." PRINT A$ + B$ '-------------------- You will see that it simply an update to the first example, but how does it work? Well when you look at it you see that infact you know how most of it works but what about the final PRINT statement? As you can see it doesn't use the speech marks. PRINT substitutes the varaibles for their values and writes the result on the screen. The + sign works differently to that of the mathematical +, in that in our example it joins the two variables together. The output of the program is this: HELLO WORLD. But 'OH MY' what happens when you actualy want to ADD two numerical values together if the + sign is used to join them together! Don't worry its easy, Qbasic follows these rules when using the plus sign: If + is used between strings (text) then join them together. If + is used between numerical values then work as a mathematical operator. If + is used between a numerical value and a string then cause an error. If all this was complicated then go back and read it over, also you could look through Qbasic's help file for more information. Another type of joining symbol is the semi-colon (;) this one can join loads of things together, even a string and a number. INPUT ----- This is another new command, that mixs PRINT, LET & KeyboardInputs all together! The best way to learn is to do, but how can you do something when you don't even know how to? confused? Well, anyway set your eyes on this: '-------------------- CLS INPUT "WHAT IS YOUR NAME"; N$ '-------------------- Let me explain the INPUT statement. The first part of it (the "WHAT IS YOUR NAME" part) works just like the PRINT command so there's nothing complicated there. However the last part is a bit different. In a way its similar to LET! Basically when you run the program you get the words WHAT IS YOUR NAME followed by a question mark. You also get a curser added to the end, this allows you to enter words and numbers from the keyboard. Once you have typed in what you need press Enter and QBasic will assign the text you typed to the variable N$ (Just like LET). Well, now that N$ has a value we could use PRINT to write it on the screen. The program looks like this: '-------------------- CLS INPUT "WHAT IS YOUR NAME"; N$ PRINT N$ '-------------------- If you wanted you could put a CLS statement inbetween the INPUT and PRINT lines. When ever QBasic encounters an INPUT statement it stops excution and waits for a reply from the keyboard. Now feast your eyes on this: '-------------------- CLS INPUT "WHAT US YOUR NAME"; NAME$ INPUT "HOW OLD ARE YOU"; AGE% CLS PRINT "HELLO " + NAME$ PRINT "YOU ARE" ; AGE% ; "YEARS OLD!" '-------------------- By now should be able to understand this. Remember the semi-colon and the + are used for joining and % means the variable type is an integer. Well thats all for now. See ya!