BASIC stands for Beginners All-Purpose Symbolic Instruction Code.
This is a basic programming language that i always recommend to people who are looking to start programming.
It is not visual basic, it may look somewhat simular, but is different in may ways.
For beginners, please learn what a variable is before moving on (try google).
NOTE ON BASIC VARIABLES:
For variables that contain letters, they must start with a $. Variables that contain only numbers do not have to start with anything. Variables are CaSe SeNsItIvE and may contain no numbers or spaces, only letters.
2. Basic Program
Lets start with a program that will ask someones name, then greet them.
CODE :
[ask]
input"Please tell me your name:"; $name
[greet]
cls
print"Hello, "; $name
print
input"Press enter to continue"; $DummyVariable
end
Now, lets go over this...
CODE :
[ask]
this is a label, labels are like shortcuts to certain parts of your code. you MUST use labels. More of this will be explained sooner.
CODE :
input"Please tell me your name:"; $name
"input" means that the user is alowed to type, and his/her response will be saved as a variable. The program will not continue until the user enters some type of input and presses enter. The text in between the quotes is the text that will be shown to the person running the program. The ; just means that there is going to be another command on that line. "$name" is the variable that the user input will be stored at.
CODE :
[greet]
Another Label, just like the first one.
CODE :
cls
This clears the screen.
CODE :
print "Hello, "; $name
"print" displays whatever is in between the quotes to the person running the program, just like input. But, this does not allow the user to put in any input. Nor does the program wait for input, it will just print it and go to the next command. "Hello, " is telling print to print everything inside the quotes to the user. ; just means there is going to be another command on the same line. "$name" prints whatever text is in that variable to the user. It prints this info because it is on the same line as print.
CODE :
print
Because this print command has no quotation marks it will just skip a line and the next line of code will operate on the line below it.
CODE :
input"Press enter to continue"; $DummyVariable
Now, this is just a common sense thing i picked up. this line prints press enter to continue and stores their input in $DummyVariable. im not planning to use $DummyVariable for anything, but the program can't continue until they put in some kind of input. The end command is next so if i just left my dummy line out, then the user would not get a chance to read the programs greeting as it would close to fast.
CODE :
end
I kinda gave away what it does above, but the end command safely closes the program for the user.
3. Outcome of chapter 2
The program prints to me:
Please tell me your name:
I enter my name (mr.toes)
The screen clears
The program prints to me:
Hello, mr.toes
Press enter to Continue
I press enter and the program closes.
TaDa!
4. A bit More Learning
Now this is why we need labels.... What it i took the program i had and chnaged it to this:
CODE :
[ask]
input"Please tell me your name:"; $name
[greet]
cls
print"Hello, "; $name
print
input"Press enter to continue"; $DummyVariable
[choose]
input "Are You Sure thats your name?:"; $Sure
if instr ("YESyes", $sure) then goto [yes]
if instr {"NOno", $Sure) then goto [ask]
goto [end]
[yes]
cls
Print "Really? If you say so..."
print
print "press enter to close this program."; $dummyvariable
end
[end]
print "You were supposed to tell me yes or no!"
print
input "Press enter to quit"; $DummyVariable
end
Now, since this is a bit longer than the first program, i will only go over the new parts.
CODE :
goto [end]
the goto command tells the program to goto the label called end. This is why labels are important, they let you manuver around your code.
CODE :
if instr ("YESyes", $sure) then goto [yes]
I use this line of code the most, lets break it down. If = it just means if, but you must have it instr = means in string, you must have this as well ("YESyes", $sure) = this part means that if the letters Y, E, S, y, e, s, are found in the variable $sure then execute the command(s) after this (on the same line only). If not, then simply ignore the rest of this line and continue the code. the brackets, quotes, and comma must be in the right place on this. then = must have this goto [yes] = this is the rest of the line, tells the program to goto the label [yes]
so the whole line means: is YES or yes is found in the variable $sure then goto the label [yes] if not, continue the code
from those last two explinations you should be able to figue out the program.
5. Version
There are many versions on BASIC, this one is liberty basic. (www.libertybasic.com) If you download the program at the site it comes with a compiler and program maker, it is free to use, as well.
6. conslusion
This brings my article to an end, i hope you enjoyed it and if its requested, i will make a second article thats longer and covers a bit move advanced stuff, mabey even some GUI.
/-Decode-\
Cast your vote on this article 10 - Highest, 1 - Lowest
Comments: Published: 18 comments.
This site is the collective work of the
HackThisSite staff. Please don't reproduce in part or whole without permission.
Page Generated: Sat, 21 Nov 2009 21:31:40 +0000 Exec:
9 Page loaded in 0.21541 seconds! Current Code Revision: 79-Stable