Begginers Tutorial 3 - Using and structuring the known commands Up to now you should at least know how to use the following: PRINT CLS LOCATE In this tutorial we use the above, but also go on to using more commands that help expand the options available to you. These commands are: GOTO/GOSUB INPUT LET First of all lets look at Goto and gosub, at this time you can use either, they both do the same thing at this level, and that is to move the flow of program reading to a different location. GOTO/GOSUB Okay, back to basics, once you run a program, the program gets read from top to bottom as i'm sure you have figured out, but programs would be very limited if that was all they could do. The goto command would take you to a label or a number in you program and then start running from there, and reading downwards again. Think of it has a water wall, and by using gosub and goto commands, you can control where it runs to first and second etc... E.g CLS gosub skip PRINT "Hello" SKIP:print "Goodbye" This is a very simple program, you first clear the screen, then you run it. Remember how the CLS statement made the Hello seem not to appear, though it actually did just too quickly to see, well in this case, it's slightly different as the program isn't actually reading the line with the hello at all, infact it's bridging over it. The Skip is just the label, it could be called anything. When using goto and gosub, always make sure you put in a label to divert the program to, and a label to recieve the flow of data from. Hopefully you fully understand that, as you know, please contact me if you have any queries. Next is the INPUT statment With most programs it is essential to be able to input data, and this is the command to do so. Lets' say as a boring thought, you wanted to input the name of an item of stock into the program (By the way, this isn't being saved, it will be lost once leaving the program), you'd simply do this... INPUT "Please enter the stock name:" ; Stock$ Alot to take in here, first of all you can see the statment INPUT at the start of the line, this tells the computer to be ready for the input 'variable' The text in the "" is what gets printed on the screen before the input, don't get confused though, you can't just use the input command to type text on the screen instead of PRINT, the computer needs a variable after it. In this case the variable is Stock$. A variable best descibed in simple terms is an number or text recognised by the computer via a string. Confused?? The string is the $ in this case (there are many other types) and that is what gives a label to the 'Stock' to tell the computer that Stock is now what ever you type in. Eg. (Not program lines) You type in answer to Please enter stock name. you type in book and press enter The computer becuase of input stock$ knows that stock$ now has a value, in this case book, and will recollect that until the program is terminated. Try this on the end of the last program: Print "Item not in stock = "; stock$ so you see how the computer has remembered the value of stock, this goes for any variable you can have stoke or stocke or anything. Also, one last thing to note, ; tells the computer that the text has finished and then executes the string following it. Try running the program without it, you'll see that it'll ask for the ; to work. So, hopefully you can input now as well. here are a few quick overviews of the main types of strings (Recapped in later tutorial for proper use) $ = Text % = Integer (Number between 1 and something like 10000 & = Long integer (Massive number 6,000,000,000) The last of the begginers tutorial commands is the LET statement This statment is again as with all the others essential in expanding program designs. The LET Command allows you to create a variable to = something or + something or / by something. It is very diverse in what it can do, here's a good exampe incorperating all of the above. CLS LET Jamie$ = "my name is jamie" LET Lawrence$ = "and my sername is lawrence" LET A% = 18 Print "Hi, ";jamie$;" ";Lawrence$;" and i'm at that sweet age of ";a%;"" Input "Do you like me?"; Z$ IF z$ = "yes" THEN GOSUB yes IF z$ = "no" THEN GOTO no e:end yes: Print "Thats nice" INPUT "Press a key to end" stop$ goto e no: Print "How horrid" INPUT "Press a key to end" Stop2$ goto e I have put somethings in you may not have seen before, though it is pretty self explanatory how they work. 'Lets'go through what's happening. We clear the screen, i am using the let command to tell the computer that i want Jamie$ to = my name is jamie. I'm using the % so we get a number, i'm printing that all on the screen in a way that it makes sence. (Th "; ;" are always needed in mid sentance if you want to bung a variable in. Then you are asked if you like me or not, this uses IF command, which basically asks the computer a question, IF this happens THEN do this, try it out. I put this in to make you think about in a program before you learn it in a tutorial as it sometimes help to work on your logic. If you say yes then it prints thats nice and similar for no, the INPUT is there not to confuse you, but to allow a stop before the end so you have to press a key to end the program, by doing this, you can see the How horrid before the program terminates. Okay, a little daunting at first look, but with programming you work through it in stages, i sometimes find it a lot easier to write a program then trying to decifer it after i've written it! and thats a fact. Anyway, thats three tutorials written in a day, not bad, hope you find it more useful then the more complicated versions out there, and as always ask if you have any worrys. Written by Jamie, for anyone