Hello again, and welcome. THis is my 6th tutorial covering the QBasic language. In this one we cover DATA...READ and file commands. To begin with we shall learn the DATA and READ commands. DATA, as you might have guessed is concerned with storing data for later use, and READ is concerned with 'reading' that data stored. They are very easy to learn and use, here look at this: '-------------------- CLS READ A$ READ B$ PRINT A$ ; B$ END DATA HELLO, WORLD '-------------------- This program might at first look menacing but in truth it is very easy to understand. Lets first concentrate on the last line. The DATA statement does not need to pass the execution line in order to work, infact if DATA is encountered during execution it will be skipped and not even looked at! (well at least thats the best way to think of it.) therefore you can place DATA after the end of the program. The READ commands can extract data away from the DATA line and store it to a variable. The first READ will extract the word 'HELLO' and store it to A$ (you should know about variables aready). This is the same for the next line too. A more compact way to do the second and third lines would be READ A$,B$ Although in this example it doesn't really matter, but might be easier when you have a lot of data to read. Next PRINT will write the variables on to the screen. Notice that the data is separated by a comma, this is how READ knows when to stop extracting data. Well that's all there is to know about READ and DATA. Lets move onto sychronous files. SYNCRONOUS FILES ---------------- Despite their name synchronous files are easy to learn. They are similar to what you have just learnt from the part above! What is a file to QBasic? Well files exist outside the QBasic enviroment, they can be text (.txt) files, documents (.doc) or any other type you can think of. I often use data files (.dat). How to create and/or write to a file... The fisrt thing you need to do is open it, and surprise, surprise you use the OPEN command. OPEN "filename.ext" FOR OUTPUT AS #1 You must give a filename to open (or create if it doesn't exist) we then use OUTPUT because we are going to 'output' data to it (alternativly you could use INPUT, but well get to that in a minute). When you open a file you have to give it a reference number, this is the job og the last part 'AS #1', the number we are giving it #1, you could open more folders each with a different number to tell them apart. OK, now that you have opened the file for the OUTPUT use you need sme way to srite data to it. This is the job of PRINT "WHAT?!" you may ask "I thought PRINT was used for writting to the screen" well the answer is yes it IS used for writting to teh screen but it can also write to files too! (Isn't Qbasic great?!) There is a little difference to the syntax though. You already have the file open so now you need to use PRINT to write to it, PRINT #1, "text" Please note that you need to replace 'text' with what ever you want (or a variable). !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! When you are finished using a file you MUST use CLOSE #1. This is very important! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (Don't worry if you do happen to forget, it will just make things a bit more complicated) Now to learn how to get the data from the file. You must first use the OPEN command: OPEN "filename.ext" FOR INPUT AS #1 You now have to use INPUT to extract the data. INPUT #1, A$ note that you must give it a variable to apply the data to! This is what you need to know to get you through syncronous files but there is still more to learn... OK now here it gets a little complicated. If you do this: '-------------------- OPEN "MYFILE.TXT" FOR OUTPUT AS #1 PRINT #1, "NUMBER 1" PRINT #1, "NUMBER 2" PRINT #1, "NUMBER 3" CLOSE #1 '-------------------- and then you were to look inside the file you created, then you'll find that those three things 'NUMBER 1, etc' are all on seperate lines! If you wanted then on the same line, but still want them to be seperate data then you must use commas. You can do this manually (Go inside the file and place a comma between every piece of data) or you could do it right from the very start and make Qbasic but commas there for you. Using what you already know you should be able to seperate the data by commas but I'll show you anyway. '-------------------- OPEN "MYFILE.TXT" FOR OUTPUT AS #1 PRINT #1, "NUMBER 1" + ","; PRINT #2, "NUMBER 2" + ","; PRINT #3, "NUMBER 3" CLOSE #1 '-------------------- Can you see how it works? First I did the normal procedure but added... + ","; to the end This will firstly add a comma to the end of 'NUMBER 1' and secondly the semicolon will tell QBasic to write whatever comes next on the same line. As you become more and more familiar to Qbasic you get used to 'when to put a semicolon' and when to put a +. If you're confused about semicolons and the plus sign the read over my second tutorial. Try to practise the things described in this installment. Try making a simple game and using synchronous files as a way of saving a top score table. Well thats all this time. If you were interested in synchronous files then look out my next tutorial which talks about Random access files. See ya!