July 20, 2024, 07:41:25 AM


Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........

stuff about CONST

Started by crystal_blox, January 23, 2009, 02:28:34 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Just like to share some things I've discovered about CONST in Creative Basic v1.01.
I find that knowing these things allows me to reorganize my code as much as I want.
People who can write their programs "in-line" (like Jolly Roger does) won't need this stuff to stay happy.

1-  When AUTODEFINE is "OFF",   then  CONST [name]  needs a preceeding  DEF [name].
1b -  They can be in the same line with a colon:

DEF black:int : CONST black=RGB(0,0,0) : ' naming common colors.

2-  I like to move my long lists of inits down to the subroutine section. 
         Of course CONST and DEF used in SUBs don't have the desired global effects.
         But they can be moved south by using GOTO and LABEL

rem   My Great Program starts here
GOTO inits : LABEL inits_ret
'  main program goes on...
'subroutines -
LABEL inits
  CONST pi=3.14
  CONST white=RGB(255,255,255)
GOTO inits_ret

3 - Don't allow a gratuitous trailing colon after CONST, particularly if it's expression uses anything more than a literal number.
      It can make a few different undesirable endings, depending on details of the expression. 
      By gratuitous I mean it looks like it's there to start another statement, but then there is only whitespace and end-of-line. 
      Autodefine ON/OFF doesn't seem to matter in this issue.

These work OK:
CONST  pi=3.14
CONST  pi=3.14 :
CONST pi=3.14 : ' a comment
CONST pi=3.14 : CONST radian=1.0 : CONST quadrant=pi*radian/2 : CONST degree=quadrant/90 : '
CONST pi=(3.14)
CONST black=RGB(0,0,0) : '
CONST black=RGB(0,0,0)

These go bad:
CONST pi=(3.14) : 
CONST pi=21.0/7.0 :
CONST pi=other_const :
CONST black=RGB(0,0,0) :

You can see the differences are subtle, but cleaning off any trailing colons after CONST makes it safe,
and is a pretty simple rule.



oops, I'm sure this is in the wrong category. 


Thanks for moving it here, Larry. -  Jim