Anyone who has done any c, cpp, c# has been warned about the evils of using global varibles. You should not use them period according to most books. My question is:
If you are not using them to excess, are they consider bad programming in Qbasic?
I'm currently working on a customized VB DB program. I've ended having to use 4 global variables. Three are standard trash/garbage containers; and 1 boolean to check if the data (aka "record" has been changed and prompt 'saving' before continuing to next screen/procedure/module/etc.)
I'd suggest if you are going to use global variables in QB you place them at the top of the main module for easier referal. This does not preclude the fact that you should abandon local variables by any means. Simply that if you have to use them ... well then use them.
There are times where speed is an issue and you can use Goto statments for speed in place of loops...
But GOTO was one of the original commands from the Line Number Days (ughhh...)...
Since then, there have been new loops added, such as DO:LOOP
And SUBs and FUNCTIONs are much easier to deal with and seperate global and local variables than GOTO/GOSUB statements...
Basically Nothing is evil or good in Basic Syntax...
The trick is to KNOW when and where to use what...
You don't want to use the same commands and methods every where...
And knowing that comes with practice and experience...
Another context effective set of commands are... Select Case:Case:Case Else:End Select
and If Then:Else:End If
Say you use A$ = Inkey$ to trap a Key...
you might use If Then Else if you only have one key to watch for... A$ = Inkey$
If A$ = Chr$(27) Then End
You Might Use Select Case in places where you check for multiple keys... A$ = Inkey$
Select Case A$
Case "A"
Print "A"
Case "B"
Print "B"
Case ""
Case else
Print "NOT A or B"
end select
And in some cases you might use an equation in place of a if then / case select... If A$=Chr$(0) + Chr$(72) then Y = Y - 5
If A$=Chr$(0) + Chr$(80) then Y = Y + 5
Can be replaced with this... Y = Y + (-5 * (A$ = Chr$(0) + Chr$(72)))
Y = Y - (-5 * (A$ = Chr$(0) + Chr$(80)))
Then simplified to... Y = Y - 5 * (A$ = Chr$(0) + Chr$(72))
Y = Y + 5 * (A$ = Chr$(0) + Chr$(80))
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.