LB Booster
Programming >> Liberty BASIC language >> LBB Macro capability
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1521065241

LBB Macro capability
Post by k6dgw on Mar 14th, 2018, 10:07pm

Does LBB have a macro capability like the "define" statement often placed in header files in C? Hypothetical example:

define NROWS=100
define NCOLS=7

dim datarec(NCOLS, NROWS)

for i=1 to NROWS
for j=1 to NCOLS
blah
blah
blah
next j
next i

Tks,

Fred
Re: LBB Macro capability
Post by RobM on Mar 15th, 2018, 04:20am

I'm not sure if it is the same idea but there is the "Let" command.

Code:
Let NROWS=100
Let NCOLS=7

dim datarec(NCOLS, NROWS)

for i=1 to NROWS
for j=1 to NCOLS
blah
blah
blah
next j
next i 

Re: LBB Macro capability
Post by Richard Russell on Mar 15th, 2018, 09:53am

on Mar 14th, 2018, 10:07pm, k6dgw wrote:
Does LBB have a macro capability like the "define" statement often placed in header files in C?

Not as such. The example you gave is not of a macro but of a constant declaration (#define can be used for both purposes).

Most BASICs (Liberty BASIC is no exception) don't have named constants, and variables must be used instead. You can adopt a naming convention (I tend to use all CAPITALS for constants) to remind you that the variable actually represents a constant and should not be altered - but unlike a true constant there's nothing stopping you.

Variables used this way will generally need to be GLOBAL, of course, so the closest approximation in LB/LBB to #define, when used to declare a constant, is:

Code:
    global NROWS, NCOLS
    NROWS = 100
    NCOLS = 7 

Macros are another issue however; Liberty BASIC has no real equivalent to macros. In some limited circumstances you may be able to leverage the EVAL function to give a similar effect, but this is not ideal.

Richard.

Re: LBB Macro capability
Post by k6dgw on Mar 15th, 2018, 4:44pm

OK. I'll have to rethink some plans, but I think I can make this work. Thanks