In this lesson, I will covor a few functions that are used in the program True Basic. This lesson will be covering VERY basic functions to get you started in this program.
First off, I would like to discuss the "Print" function. The print function is used to make your compiler show text in your output window. The proper way to use Print is when you are using a mathematical expression such as "4+1" or "4^2". When programming in True Basic, the variables you use to create a mathematical expression are as follows:
* - Multiply
/ - Divide
^ - To the power of
- - Subtract
= Equals (used when writing "Let" statements)
+ -Addition
When writing a mathematical expression, True Basic uses the order of operations, also known as "PEMDAS" (Perenthasis, Exponents, Multiplication, Division, Addition, Subtraction). When you are writing your code, you will need to use the order of operations if you want to use a long algebra problem. An example is this:
If you use the following code:
This will give you the answer "38" in the output window. This is fine if you are making an algebraic expression this way, but if you are trying to make your statement do 4+5 and then multiply that answer by 10*2, it will not do that. It will just do the operation number by number. If you want it to do the equation by parts, you need to use perenthasis. The code should look like this:
This will tell the compiler to do 4+5 first and then add whatever 10*2 is, which happens to be 20. Your new answer will be "29" in the output window.
**NOTE** The compiler does not recognize multiplication inbetween parenthasis. If you were doing a problem such as 5+5*4+5, you would have to type this in the source window:
If you type the following, the compiler won't know what to do with the product that it got from the parenthesis.
So ALWAYS remember to put an asterisk (*) inbetween your parenthesis.
END STATEMENT
And True Basic, like most other programs, you will need an "End" statement at the end of your code. If you don't have one, the compiler won't know what to do with the information you have put into the source window.
SEMICOLONS AND QUOTATION MARKS
When programming in True Basic, you need to use quotation marks when youm want specific text to show in the output window. If I want my output window to say "Hello everyone, my name is Brandon", I will have to wrap my text in quotation marks.
What do you think will happen when you type this code in the compiler?
Quote:
Print Hi my name is Brandon
END
|
If you said it will give you an error, you are correct. When entering text after a statement, you always use quotation marks because when you don't, the compiler will think you are trying to do a mathematical equation. The compiler notices that none of the letters from "Hi my name is Brandon" are one of the functions that are used in a math equation. The correct way to do this would be:
Quote:
Print "Hi my name is Brandon"
END
|
Now that you know when to use parenthasis, you need to know how to use semicolons. In True Basic, semicolons are used to tell the compiler that you are done with using quotations and want to do a mathematical equation. If you want your output window to say "The number of kids in the class is 5" and you want 5 to equal the answer of a mathematical equation, you will need to put a semicolon after your ending quotation mark. Here's what it should look like:
Quote:
Print "The number of kids in the class is"; 3+2
END
|
This will tell the compiler that you are done puting text in the output window and that anything after the semicolon will be a mathematical expression. You can also use more than 1 semicolon on a line of code. If you wanted the output window to say "I have 2 brothers that were both born in October" you would write the following code:
Quote:
Print "I have"; 1+1; "brothers that were born in October"
END
|
The semicolon not only says that you are done with your quotations, but it also tells the compiler that you are done with a mathematical equation.
USING LET STATEMENTS
In True Basic, when you are defining a variable, you use what's called a "Let" statement. Let statements are used to tell the compiler that anytime a certain phrase is used in your code, the output window will give it a specific value. Here's an example of using a Let statement.
Quote:
Let brother1 = 5
Let brother2 = 10
Print "I have 2 brothers. They were both born in October. The sum of my brothers ages combined are"; brother1+brother2
END
|
This will tell the compiler that when you type in brother1, it will give it the value "5" and when you typr brother2, it will give it the value "10". In your output window, you will get the following result:
Quote:
|
I have 2 brothers. They were both born in October. The sum of my brothers ages combined are 15
|
When using a let statment, it will define the variable for everything under that let statement and nothing above it. If you were to put the Let statement UNDERNEATH where your mathematical equation is, it will give you an error that you are not using a correct mathematical function because your compiler doesn't know what brother1 or brother2 is. When you use a let statement, it tells the compiler that brother1 = 5 and brother2 = 10.
If you want to assign brother1 and brother2 a different value for the coding after your "Brother sum" statement, you can define it again. If you want to assign brother1 as 6 and brother 2 as 11, your code will look like this:
Quote:
Let brother1 = 5
Let brother2 = 10
Print "I have 2 brothers. They were both born in October. The sum of my brothers ages combined are"; brother1+brother2
Let brother1 = 6
Let brother2 = 11
Print "My brother just had their birthday, the new sum of their ages is"; brother1+brother2
END
|
Since you defined brother1 and brother2 again, anything BELOW your newely defined variabled will be effected by this. All coding above the new let statement stays as it was before.
Now that I have explained some of the basic of True Basic, I hope that you have gained farther knowledge of the program. By reading this, you may even want to start programming in True Basic. Who knows? I hope to write more lessons in the future. -EATME