BBC BASIC for Windows
« #define »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:55pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: #define  (Read 766 times)
kgoodyer
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx #define
« Thread started 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
« Last Edit: Nov 18th, 2013, 9:51pm by kgoodyer » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: #define
« Reply #1 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.
« Last Edit: Nov 18th, 2013, 10:10pm by admin » User IP Logged

kgoodyer
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Re: #define
« Reply #2 on: Nov 18th, 2013, 10:14pm »

Richard your a STAR thank you!!!

... and thanks for correcting my boolean!
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls