BBC BASIC for Windows
Programming >> Operating System >> #define
http://bb4w.conforums.com/index.cgi?board=os&action=display&num=1384815028

#define
Post by kgoodyer on Nov 18th, 2013, 9:50pm

Is there a way of defining something in BB4W? I have some code that needs to do allot of trading with various windows API's. When I want to pass a 'command' I am currently having to work out the value of the command from the windows .h file and insert it as a binary number in the SYS call.

So instead of doing...

Code:
SYS `setlights` 7 TO r% 


I could do something like

Code:
#define switch_on_red     0x00000001
#define switch_on_blue    0x00000010
#define switch_on_green 0x00000100

SYS `setlights` switch_on_red AND switch_on_blue AND switch_on_green TO r% 


I guess I want to create a BB4W version of some of my favourite C header files.

Thanks in advance.
Keith
Re: #define
Post by admin on Nov 18th, 2013, 10:08pm

on Nov 18th, 2013, 9:50pm, kgoodyer wrote:
Is there away of defining something in BB4W? I have some code that needs to do allot of trading with various windows API's

BBC BASIC doesn't have named constants, so you have to use regular variables instead. To emphasise that it's really a constant, I recommend adopting a naming convention. Since Windows constants consist of entirely CAPITAL letters (often with one or more underscores) that's the recommended convention.

So using that convention your code becomes:

Code:
      SWITCH_ON_RED   = &00000001
      SWITCH_ON_BLUE  = &00000010
      SWITCH_ON_GREEN = &00000100

      SYS `setlights` SWITCH_ON_RED OR SWITCH_ON_BLUE OR SWITCH_ON_GREEN TO r% 

(I've changed the AND to OR, because with the values you've listed ANDing them together gives zero!)

Quote:
I want to create a BB4W version of some of my favourite C header files.

Don't forget the Windows Constants utility which ships with BB4W (slot 8 in the Utilities menu, usually). That knows all the common Windows constants, so you don't need to mess around with header files.

Richard.

Re: #define
Post by kgoodyer on Nov 18th, 2013, 10:14pm

Richard your a STAR thank you!!!

... and thanks for correcting my boolean!