How to declare a constant in BASIC


How to declare a constant in BASIC



Unfortunately, I’m having trouble figuring out how to do some things, because Google is clogged with tutorials of “programming basics” and Visual Basic.



So I have to ask: in old-skool BASIC, I know I can use constants like #RED, but how do I define a constant?


#RED





This might be better for retrocomputing SE, but afaik, there are a multitude of "old-skool" BASICs and many likely have variations in syntax
– 0 0
Jun 25 at 15:13





As James eluded to, there is no one correct answer, however -most- versions of BASIC used the keyword CONST. Those that did not have such a keyword the programmer usually had his/her own style of naming including all capital letters, underscores, pre-pending names with "CONST_" or some similar method to regular variables. I'm not aware of -any- flavor of BASIC that would have recognized "#RED"
– Bill Hileman
Jun 25 at 17:23





I honestly don't remember any "old-school" BASICs that actually supported constants; those that did, mostly post-dated QBASIC/QuickBASIC.
– Jeff Zeitlin
Jun 25 at 18:09




2 Answers
2



Normally, in most dialects of Qbasic allow the value of a number to be assigned to a constant, such as:


10 CONST VALUE = 10



then other constants can include them:


20 CONST VALUE2 = VALUE * VALUE



there is also the DEF FN function which includes a declared function..



In most dialects of Qbasic there is a declared function:


DEF FNA(X) = X * 10
PRINT FNA(10)



which declares the defined function.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?