[home] [<-back] [index] [next->]
**********************[ b 0 g - [ a r t i c l e # 10 ]********************** $ by: n1e $ **************************************************************************** ** [ Q B A S I C ] ** **************************************************************************** Do you ever need a simple program and you dont want to fumble with a complex programming language like C to make it? Need something Quick, easy to make, and works efficient? Believe it or not, if you have MS-DOS (not the version that comes with Windows), then you also have a very powerful, yet simple programming tool called QBASIC. The version of QB you get with DOS is not the compiler version, so you cannot make executables with it, but there is a way around this i will explain in a little bit. First thing you need to do is open the MS-DOS prompt from windows, type: qbasic then hit enter. If you have used MS-Edit before than you will notice it looks almost exactly like it, and it should be somewhat easier to figure out. A window will pop up when you first enter the program, hit escape to close this window. now you will have an untitled file just waiting for your fingertips to fill it up. Lets start by writing the forever popular Hello World! program. 1 CLS PRINT "Hello World!" END Now try running the program by hitting Alt, R, then Enter. If you did not make any typos it will run the program and you will see a blank screen with 'Hello World!' at the top and 'Press Any Key To Continue' at the bottom. How it worked: 1 (The line number, not really needed in QBASIC unless you use GOTO commands) CLS (Clears the screen of any text or graphics) PRINT "Hello World!" (Prints any text encircled by the "s) END (Tells the computer that this is the end of the program) Now lets go a little more in-depth with some more powerful commands. 1 CLS INPUT "What is your name"; name$ CLS PRINT "Hello"; name$ END Now if you run this program you will first be prompted a question, 'What is your name?', you can type in anything you want here (it cannot go over a certain amount of characters, but i forgot how many). Next when you press enter it will say 'Hello Joe Lamer' (or whatever you said your name was), then it will end. How it worked: First I must point out the this ---] name$ What is this you ask? It is called a variable, a variable in algebra is a number with no given value, in QBASIC it is the same thing, only it can be letters also. it can also be called anything you like it to be called as long as it does not go over 30 characters (I think) and that it has a $ at the end of it. Example: stupidnameforavariable$ 1 CLS INPUT "What is your name"; name$ (Asks for input and assigns the input to the variable) CLS PRINT "Hello"; name$ (says 'Hello' and also prints the variable) END Now your thinking, this is cool, but I have to open this QBASIC program to run the programs, I sure as hell don't want to do that. Well guess what, there is a way around this, all you have to do is this: 1. open a text editor program and write the following: @qbasic /run programname.bas 2. Save this as programname.bat (programname is whatever you named your program, duh). 3. put the file in the same directory you saved your program What you just did is simple, you made a file called a batch file. Batch files run a series of commands that you dont want to type over and over again at the DOS prompt. One example is autoexec.bat in your C: directory. This batch file is run every time you start your computer to set up sound cards, video cards, start windows, run virus scan, etc. If you wanted to, you could put the above commands at the bottom of your autoexec.bat so every time you start your computer it runs that program. If your really good at ASCII art you could make a QB program to print out a kewl logo every time you started up your PC. Or.... you could even make your PC password protected at startup like this: 1 CLS INPUT "Please enter your password now ", passwd$ IF passwd$ = "yourpasswordgoeshere" THEN GOTO 2 CLS PRINT "INCORRECT PASSWORD!!! Please try again." SLEEP 1 GOTO 1 2 END Note: This program would be easy to bypass if you forgot your password, all you would have to do is restart your computer then hold shift as soon as you see it say 'Sarting MS-DOS'. You would keep your hand on the shift key until you see the "C:]" come up, then let go. The shift key tells the computer not to load the autoexec.bat or config.sys file. You would have access to the computer but might not be able to start windows because of drivers not being loaded. Then you could open up your program and change the password and reset the PC. Now your thinking, so what good is this program if somebody can just hold the shift key? Believe it or not, most people are not too smart when it comes to DOS, in fact, I know people who are actually afraid of it. So you could easily keep your little brother or sister of your computer, but if you invited a hacker over to get through your password, he would laugh at you. How it worked: 1 CLS INPUT "Please enter your password now ", passwd$ IF passwd$ = "yourpasswordgoeshere" THEN GOTO 2 (this compares the variable with the password, CLS if it is correct it will go to line 2, if not PRINT "INCORRECT PASSWORD!!! Please try again." it will just continue the program) SLEEP 1 (This tells the PC to wait one sec, then go on) GOTO 1 (This tells the PC to go to line 1) 2 END Don't be afraid to play with the programs a little bit, none of the commands i included here can damage your computer. What you just learned is only the tip of the iceberg, QBASIC can do much much more than just this simple crap. You can do graphics and sounds with QBASIC, and complex math functions. If you enjoyed programming in this language, then I suggest you get a copy of QBASIC for Dummies, the printing company is called IDG. The book is very easy to follow, and gives a better understanding of QBASIC. Hope you enjoyed this article. niemand1 **EOF** $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $- $