In this short tutorial, you will learn how to add an access code to your True Basic program.
First of all, start True Basic
What you want to do first is execute your loop statement. To do so, enter "Do" into True Basic. This will tell the compiler that you wish you begin a loop.
Now what you want to do is give the user a way to enter the code. To do so, we will be using an Input Prompt. Input Prompt is a statement that allows you to combine a Print statement and an Input statement into 1 line of code. To do so, enter the following code:
Quote:
|
Input prompt "Code: ": code$
|
In past lessons, you have learned that you need to use a dollar sign ($) which initiates a string variable. If your code is NOT a word, you can remove the dollar sign. If you have any letters in your code, you will need to add the dollar sign.
Now we need to initialize an if statement. If statements are used to look at the variable you are comparing and see if the condition is true or false. In this case, we will be using an "equal to" if statement. To do so, enter the following code:
Where "open" is, you will replace it with the code that you would like to protect your program with. In this case, I have used "open" as my code.
Not we need to tell the compiler what to do if the if statement is true.
Enter the following code:
You can put anything you would like in the print statement, but try to make it say something along the lines of "Approved" or "You're in" because the user needs to know if they have accessed the program or not.
Now we need to tell the compiler what to do if the if statement is false. To do so, we will be using an else statement. Enter "else" into a new line of code and then press enter.
Now we need to tell the compiler what to do when the condition is false. To do so, we will use another print statement:
Again, you can enter anything you'd like for this print statement. Since we've finished our if statement, we need to end it. To do so, enter "end if" on a new line of code.
Now we need to execute a loop statement. To do so, enter the following code:
Quote:
|
Loop until code$ = "open"
|
Since my code is "open", I have told the compiler to loop all of the data underneath the "Do" statement until the condition (code$) is true. Where "open" is, you would enter what ever value you assigned for code$.
Add this to the beginning of your program for a fast and simple code required access.
Your final product should look like this:
Quote:
DO
INPUT prompt "Code: ": code$
IF code$ = "open" then
PRINT "Access approved!"
ELSE
PRINT "ACCESS DENIED!"
END IF
LOOP until code$ = "open"
|
WRITTEN BY FICTICIOUS ON DECEMBER 4TH, 2006