Qbasic Tutorial for beginners and children (Under Construction)


BUGS caused by Misspelled variables

One of the most common bugs in BASIC programming is misspelled variable names. I often encountered the following mistakes while teaching BASIC to beginners:

 

length = 10

Breadth = 5

area = lenght * breadth 

PRINT area

The variable "length" is wrongly spelled in the 3rd line. BASIC differentiates between "length" and "lenght". It will look for the value of variable "lenght" in the memory. Since it could not find it, BASIC will assign 0 to the variable. 

So when you print the contents of variable "area", you will get a 0 instead of 50.

Unfortunately, apart from checking whether your variable was correctly written, we can't do much to prevent these types of mistakes. However if you are working in VBDOS, use the  OPTION EXPLICIT  statement to force all variables to be declared. The program will tell you that variable "lenght" has not been declared, giving you the opportunity to correct your mistake.

[ Previous Index Next ]


pages viewed since January  19 2002