----------------------------------------------------------------------- Tutorial 3: Formatting Text-----------------------------------------------------------------------Yep. That's the name of my third tutorial. Today you'll learn how to read certain parts of a string, make text different colors, and make them upper or lower case. You'll also learn how to put text at a certain point on the screen. That's about it for now. Just keep on reading.You'll be learning these commands today:COLORLEFT$RIGHT$MID$LOCATETABUCASE$LCASE$So, let's get going!-----------------------COLOR----------------------- COLOR lets you change the color of text you put on the screen.It's very simple to understand. The syntax is: COLOR [foreground color] , [background color] , [border color] . Foreground is the color that the text is. Background is the color that the area around the letter is. Border color is supposed to set the border to the screen, but doesn't do anything that I can see! if you put COLOR in the program, it changes the color of all of the text printed until the next COLOR statement. For example, if you typed "COLOR 1, 4", it would PRINT blue text with a red background. If you typed "COLOR 2, 9", it would PRINT green text with a light green background. Understand? It's pretty easy. Now you need to know the basic fifteen color codes. Well, guess what? They're right here:0 - Black1 - Blue2 - Green3 - Light Blue4 - Red5 - Purple6 - Brown7 - Light Grey8 - Dark Grey9 - Light Blue (A little darker than #3)10 - Light Green11 - Turquoise12 - Light Red13 - Light Purple14 - Yellow15 - White After you use these colors for a while, you memorize them.Recap:-COLOR changes the color of text that you PRINT on the screen.-The syntax is COLOR [foreground color] , [background color] Foreground is the actual text color and background is the background color. A comma must always seperate the two numbers.-COLOR changes the text color until the end of the program or until the next COLOR statement.-----------------------LEFT$----------------------- LEFT$ is the first of the three string splitter-uppers. It takes a string expression and breaks it into seperate parts. The syntax is LEFT$ (stringexpression$, number of characters) . Stringexpression$ is the string variable or the text that you want part of. The number of characters is the number of characters you want left of the first character in the expression returned. It takes the characters starting with the furthest left character and going right the number of characters specified and returning them. LEFT$ can be used in PRINT statements and in LET statements. Here's what it looks like: PRINT LEFT$ ("Take a bite out of crime", 9) This writes the first nine characters from the first character, which is "Take a bi". That's what's written on the screen. LEFT$ can also look like this: "MA$ = LEFT$ (dod$, 5)". This makes the variable MA$ equal to the first five characters of the variable dod$. That's the LEFT$ command.Recap:-LEFT$ splits up strings from the leftmost character on.-The syntax is LEFT$ is LEFT$ (stringexpression, number of characters) stringexpression is either a string variable or an expression in quotes. Number of characters is the number of characters you want the computer to read from the left of the expression.-This comand can be used with PRINT statements or LET statements.-----------------------RIGHT$----------------------- We won't go into this one as much as we did with the LEFT$ command. It's basically the same thing, just backwards. It's syntax is RIGHT$ (stringexpression, number of characters) . Stringexpression is a string or expression and number of characters is the number of characters you want the computer to read and return. It looks like this: PRINT RIGHT$ ("Oh my God! They killed Kenny!", 13) "killed Kenny!" is PRINTed. Recap:-RIGHT$ Splits up words from the rightmost character on. -This is exactly the same as LEFT$, it just starts from the right side.-This works with the PRINT and LET statements.-----------------------MID$----------------------- MID$ reads string variables. starting midway through a string or expression, and continues until a specified point to stop. This is a lot like LEFT$ and RIGHT$, but a little more complicated. The syntax is: MID$ (stringexpression$, start%, length%) . Stringexpression$ is either a string variable or an expression in quotes. Start% is the charachter number that the computer should begin reading on. Length% is the amount of charachters you want the computer to read (going from left to right). MID$ can be used with PRINT or LET statements. It would look something like this: PRINT MID$ ("Green Grow The Rushes Ho!", 7, 8). That line would PRINT "Grow The". It started reading on the seventh character, the G on Grow and continued reading until the e on The, which was eight characters away. This line: A$=MID$ ("Huzzah!", 3, 2) would store "zz" in A$.Recap:-MID$ reads part of a variable and writes it to a variable or displays.-The syntax is: MID$ (stringexpression$, start%, lenght%). Stringexpression$ stands for a string variable or an expression in quotes. Start% is the character number that you tell the computer to start reading on. Length% is the amount of characters you want the computer to read for.-MID$ can be used with LET or PRINT statements. -----------------------LOCATE----------------------- LOCATE lets you put text at a certain place on the screen. Imagine the screen as a grid with a whole bunch of places that you can put letters. When you use a PRINT statement to write text on the screen, it, by default, starts on the first open space on the screen - usually the top left corner. You can't decide exactly what place on that grid to put your character without a whole bunch of PRINT statements and spaces - unless you use the LOCATE command. The syntax is: LOCATE [row%] , [column%] , [cursor%] , [start%] , [stop%] . The most important parts are row% and column%. They tell the computer what space on the imaginary grid to start putting the text at. Cursor% tells the computer if you want the cursor shown after the text you PRINT. If you put a one there, it is shown, and a zero makes it not-shown. LOCATE looks like this while in a program: LOCATE 10, 12 . It doesn't do anything unless followed by a PRINT statement. If that LOCATE statement was put in front of a PRINT statement, the next thing PRINTed would be LOCATEd at that place on the screen. If this line: LOCATE 18, 24 : PRINT "I want Pringles!" was in a program, the computer would go to the eighteenth row down, and then go to the twenty - fourth space over and PRINT I want Pringles! Don't worry about the other three attributes - I've only needed to use one of them in one of my program once. NOTE: There are different numbers of rows and columns depending on the screen mode. You'll learn about screens in tutorial five.Recap:-LOCATE PRINTs text on the screen at a certain point on an imaginary grid. -The syntax is: LOCATE row%, column%. There are other attributes - you [probably] won't need them.-The next PRINT command after the LOCATE command is PRINTed at the specified location.-The number of rows and columns varies with screen mode.-----------------------UCASE$----------------------- UCASE$ makes any string or expression have only capital letters. This takes any lower case letter (askii characters 97 to 122) equal to their capital form (askii character 65 to 90). This is very useful for reading input which may be inputted in capitals, lowercase, or mixed. LCASE$ is almost the same, it just does the opposite. The syntax for UCASE$ is: UCASE$ (stringexpression). Pretty simple, right. UCASE$ ("Happy Happy Joy Joy!"). Would return "HAPPY HAPPY JOY JOY!". UCASE$, like LEFT$, MID$ and RIGHT$ must be used with a PRINT or LET statement.Recap:-UCASE$ makes any string variable or expression completely capital.-The syntax is: UCASE$ (stringexpression) Variableexpression must be in parenthesis and must be a string variable or a text expression.-----------------------LCASE$----------------------- LCASE$ is exactly the same as UCASE$, just changes the letters to lowercase instead of uppercase. This takes any uppercase letter (askii character 65 to 90) equal to their lowercase form (askii characters 97 to 122). This is very useful for reading input which may be inputted in capitals, lowercase, or mixed. The syntax for LCASE$ is: LCASE$ (stringexpression). Pretty simple, right? LCASE$ ("Happy Happy Joy Joy!"). Would return "happy happy joy joy!". LCASE$, like LEFT$, MID$ and RIGHT$ must be used with a PRINT or LET statement. Recap:-LASE$ makes any string variable or expression completely lowercase.-The syntax is: LCASE$ (stringexpression) Variableexpression must be in parenthesis and must be a string variable or a text expression.-----------------------TAB----------------------- TAB is a command meant to be used with the PRINT command. It is a primitive form of LOCATE. It moves the starting PRINTing point over a few spaces (columns). It is put between PRINT and the expression you want PRINTed. It looks like this: PRINT TAB(25); "Rugga-Rugga!". This PRINTs Rugga-Rugga! twenty five spaces to the right. It's very easy to understand. Just change the expression and the number of spaces in that statement and you're set!Recap:-TAB is used with the PRINT statement to PRINT text a specified number of columns to the right.-The syntax is: PRINT TAB(number%); [stringexpression]-----------------------Challenges:-----------------------1.) Add some colored text and make some text centered in Guess The Number (The one in the answers to challenges for tutoriall #2.) Make it look spiffy!2.) Make a simple program with color askii graphics where you press enter to shoot something. Make it have bullets move across the screen and have something random happen in it. It should be challenging, but not too hard. The target, your gun, or both should move. Make it cool!3.) Make an askii character, colored screen saver with something that bounces around or goes back and forth. Use the LOCATE command.4.) Incorporate colored text or graphics into the text adventure - or both. Center some text, and make it look nice. Add some more rooms while you're at it - and make some more choices.5.) Make a program where your first and last name. The program should split it up and save the first name in one variable and the last name in another. Then it should PRINT your first and last name.-----------------------Final Thoughts:----------------------- Well that was my second tutorial. You should be able to make half-decent programs now. Make a full length text adventure! That would be cool! You should be able to do it - if you can't, reread tutorials two and three. I'm sure you want to start making some five star, topnotch game like Wetspot 2, but take a few days to make some simple games. Their fast and easy to make, not to mention fun! One of my first games was TOWER.BAS, which was a real hit in my seventh grade computers class. It only used simple commands, but it was fun and easy to understand. Everyone got a copy from my disk and altered it to fit their needs. There were probably fifty different versions of my stupid little game using only commands I've taught you so far (except for INKEY$ which you'll be learning in tutorial #4). Well, have fun programming until tutorial three which will be along in about two weeks. This one was exactly one day less than two weeks after tutorial two and three were released!-PeteDecember 19, 1998