======================================== 5. A very BASIC tutorial - John Casson ======================================== >Note from Screech: >This article contained a few errors when I read it, I may have missed a few - this means that >not everything contained in this article is correct, but it is highly unlikely that anything is >uncorrect. Overall this is a very good article though, so get reading beginners. >Send him your comments at: J_cass1@hotmail.com This is a paper written by John Casson for the BASIX Newsletter, I decided to write this article because of the lack of beginners tutorials on the web. When I say run the program, I mean click on run then click on start. This will run the code that is in the main window. The first command that I am going to tell you about is REM, this command basically means REMARK and it is ignored by the compiler so it is used for programming notes, it can also be written as ' (The single speechmark) here is an example: PRINT "Hello" 'This command displays Hello on the screen I: CLS CLS is a command used to Clear the Screen. This command will clear any text that was printed on the screen and any graphic objects on the screen. This will become useful later in the paper, but for now don't worry about it. II: PRINT Print is a command used to put some text on a screen. If you typed in the following line of code into Qbasic/Quickbasic: PRINT "Hello" If you run this program you will see the word Hello written in the top left hand corner of the screen. You can use the print command to put text anywhere on the screen, which brings us onto the next topic. III: LOCATE Locate is used to tell qbasic/quickbasic where on the screen to put some text using the print command. Here is an example: CLS LOCATE 5, 6 PRINT "Hello" Now I will take you through the program line by line: -------------------------------------------------------------------------------- CLS 'This command clears the screen. Locate 5, 6 'This command tells Qbasic/quickbasic that you want to put text 'in at the fifth row, in the sixth column. -------------------------------------------------------------------------------- Print "Hello" This command, as you know places text onto a screen, but in this program, it will put it on at the fifth row, in the sixth column. IV: Input Input is used to receive input from the keyboard and to store it in a variable. There are many ways in which to store this information that can be received from the keyboard. You could store it as a whole number, a decimal number or you could store it as text. This means that you can store a string of text in a place with a name that you can specify. For example, if you kept someone's name in a variable and the variable's name was NAME1$ (the dollar sign after the title of the variable tells qbasic/quickbasic that NAME1$ is a STRING) then you could use the print command to print on screen the text that is contained in name1$. Here is an example: CLS 'Clear the screen INPUT "What is your name? ", A$ 'Prompts the user for input and stores it in the STRING A$ PRINT "Hi "; A$ 'Prints "Hi " onto the screen followed by the contents of A$ 'the speechmarks will NOT be printed Here is a line by line walk through of this program: IV: Color (Notice the American spelling) Color is the command used to change the color of the text. You do not type in the name of the color, you type in the number corresponding to the color. 0 = black 4 = red 8 = gray 12 = light red 1 = blue 5 = magenta 9 = light blue 13 = light magenta 2 = green 6 = brown 10 = light green 14 = yellow 3 = cyan 7 = white 11 = light cyan 15 = bright white This is a table that shows which number corresponds to which color. Here is an example program: CLS 'Clear the screen COLOR 4 'Change to colour RED PRINT "RED" 'Print "RED" on the screen(in RED) COLOR 2 'Change to GREEN PRINT "GREEN" 'Print "GREEN" on the screen(in GREEN) COLOR 14 'Change to YELLOW PRINT "YELLOW" 'Print "YELLOW" on the screen(in YELLOW) What this program does is clears the screen, sets a color, and prints some text in that color. V: IF and THEN IF and THEN are commands used in BASIC like this: IF I am hungry THEN I eat. This would not work in BASIC, but this would: IF 10+2 = 12 then print "hi" What this line says is that if ten + two is twelve then write at the next point on screen hi. We will use IF and THEN later on in the tutorial. VI: Variables A variable is where you store your information, it is usually named after what the information being stored in it is, for example I would store a persons name in a variable called NAME$, the dollar sign will be explained later. We said before that you can store information in variable. So if you wrote the following line of code in to qbasic/quickbasic it would save the number 15 to the variable A%. The % after the name of the variable makes it into an INTEGER(a whole number without a decimal place) A% = 15 If we use the print command with a variable, we can find out what information is in it. Here is a sample program that tells you what number is stored in the variable A% CLS A% = 1+1 PRINT A% This program clears the screen then adds one and one and stores the answer in a variable called A%. The last command print the information in the variable called A%. CONCLUSION This is the end of this paper on BASIC, but there will be more! I am going to finish off with a long program that uses all of the commands that were listed in this document. CLS LOCATE 5,5 COLOR 14 PRINT "THIS IS THE FINAL PROGRAM OF THIS TUTORIAL. A% = 5 + 5 PRINT "WHAT IS 5 + 5?" INPUT B% IF A% = B% THEN PRINT "YOU GOT IT RIGHT" This is the end of the tutorial! I will be writing more tutorials to follow this on soon, so keep on checking the newsletter! John Casson ---------------------------------------------------------------------------------- This tutorial originally appeared in the BASIX Newsletter, Issue 2 from July, 1999. It was written by John Casson.