--------- Face Lift --------- Qbasic is a high level langauge. This is good because it is a Hell of a lot easier to learn then C++ or Java. This is bad because it compiles it into large EXE's and the programs are slower than lower level computer languages. So, you have to learn to milk every bit of speed out of BASIC. One way to do so is with Signed numbers. This means you added one of thoughs symbol thingys(%, $, !, etc) to a variable so Qbasic know what it is (an integer, String, long, etc). As you know, looping is one of the slowest things you can do in Qbasic. But if you use x% instead of x, Qbasic doesn't have to spend as much time figuring out what type of variable its dealing with, and instead can devote all its power to looping as fast as possible. I did the following on an old IBM XT s = TIMER FOR x% = 1 to 100 FOR y% = 1 to 100 NEXT y% NEXT x% PRINT TIMER - s This took the computer 1.701 seconds to complete.I did the following on the same computer, using unsigned( no little symbol thingys) varibles: s = TIMER FOR x = 1 to 100 FOR y = 1 to 100 NEXT y NEXT x PRINT TIMER - s This took the computer 16.91 seconds to complete. I did the test several other times on the XT, than 3 times on a 386sx, and then 3 times on a 486. Each time the first method was between 91.5% and 89.5% faster than the second. to get these numbers I used the folling formula: (SPEED OF SECOND METHOD - SPEED OF FIRST METHOD) / (SPEED OF SECOND METHOD) You multiply this number by 100 to get a percentage. Go ahead try them on your computer and compare the time on each. I used this method to rapidly speed up the movement algorithm in "VOICES OF LIBERTY" (tm), by Acidus Software. Another way Qbasic programs are slowed down alot is through the use of subs/functions. Many programs use the "DIM SHARED (variable)" to create variables that can be used by all subs/functions. This is ok, but everytime Qbasic calls that sub, it must not only pass all variables need for the sub/function, but it also passes ALL the DIM SHARED variables. Lets say you had code that looked like this: DECLARE SUB somecoolsub (text$,value1,value2) DIM SHARED Globalvar1 DIM SHARED Globalvar2 DIM SHARED Globalvar3 somecoolsub "neato", 99, 10 END When you compile this, it is turned into: DECLARE SUB somecoolsub (text$,value1,value2,Globalvar1,Globalvar2,Globalvar3) DIM SHARED Globalvar1 DIM SHARED Globalvar2 DIM SHARED Globalvar3 somecoolsub "neato", 99, 10, Globalvar1, Globalvar2, Globalvar3 END If you repeatedly call this sub/function, it makes the EXE bigger, and the sub/function takes longer to load. Also, as mentioned before, ALWAYS use signed variables, even if you are DECLAREing a function. For Example DECLARE FUNCTION areaoftri% ( length%, width%) ... FUNCTION areaoftri% ( length%, width%) areaoftri% = length% * width% * .5 END FUNCTION Executes at the same "91.5% and 89.5% faster" ratio than if you used: DECLARE FUNCTION areaoftri ( length, width) ... FUNCTION areaoftri ( length, width) areaoftri = length * width * .5 END FUNCTION If you have read the article "Boolean Hell," then you know that 0 is false and 1 is true. Well, that is only have right. In Qbasic, 0 is false, and everyting else is true. The 2 following lines do the same thing, assuming that IHaveTheKey% does equal 1. IF IHaveTheKey% = 1 THEN UnlockDoor IF IHaveTheKey% THEN UnlockDoor The second one works just like the first one, reduces program size by 3 bytes, and runs about 50% faster because Qbasic doesn't have to compare it with anything. Another example is: INPUT "Name:",TheirName$ IF LEN(TheirName$) >=1 then goto PassWordCheck INPUT "Name:",TheirName$ IF LEN(TheirName$) then goto PassWordCheck Also along the lines of math, Qbasic is STUPID. If you give it a line like: sum= y1*x+y2*x+y3*x You can reduce time by FACTORING IT DOWN. Yes, and you thought sleeping through Algebra II wouldn't cause you to miss anything good! (Boy was I screwed this year in Calculus!). Just like me struggling to do this problem with 1 minute left for a test, it takes BASIC a long time. If I wasn't so stressed, I would have seen that "sum= y1*x+y2*x+y3*x" and "sum = x(y1+y2+y3)" were then same thing. Well Hell, the second was is much easier. Qbasic's child like mind thinks the same way, and will solve "sum = x(y1+y2+y3)" a hell of alot faster than "sum= y1*x+y2*x+y3*x" The Lesson: make the math as simple as possible for Qbasic. Oh here is something I ran across in a TXT file once, but the programmers name wasn't one it, so I can't give credit, sorry, but I DIDN'T figure this one out on my own. For some god awful reason if you use "\" to divide integers instead of "/", it goes WAY faster. The only thing is if you get a decimal as an answer, if rounds, as if the INT function was used. Weird Huh!?! ALWAYS USE SIGNED VARIBLES! It cuts down on the speed, and the size of the .EXE files you make. While on the topic of EXEs, there are a few ways to make better compiled programs. First of all, NEVER EVER EVER compile a program so the program needs BRUN41.LIB (or VBRUN300, etc.) to run. If you widely distribute your program, you have no way of knowing if whoever downloads your program has that file. Plus it looks SO unprofessional. The ONLY reason you would want to do this is you have alot of programs in the same directory that need this file. Compiling in this way makes the .EXE smaller, but with how cheap gigabytes are, it is pointless to use this method to save 20 kilobytes. Also, .COM files load and run much faster than .EXE files. Look around on the internet, and you can find a shareware EXE2COM file. This makes the file smaller and faster, and more professional. Well, thoughs are all the ways to squeeze every bit of speed out of Qbasic programs I've found on my own (except that one :-0). If you find anymore, please contact me. -------------------------------------------------------------------------------- This tutorial originally appeared in the QBasic Developers Forum, Issue #2. This was written by Lord Acidus.