Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Codger
23
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 26th Oct 2003 04:10 Edited at: 26th Oct 2003 04:13
As I have used DBP for quite a while I was suprised to find that #CONSTANT had a range of uses.

I understood #CONSTANT was use for

#CONSTANT PI = 3.142

I did not realize it could also serve a more complex dynamic role

#CONSTANT TEMP = print int((rnd(10)-5))*.01



As thier is no documentation on this I decided to post so that others could see different ways to use this feature.


Anyone know of other undocumented "Tips"?

System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX
levent
23
Years of Service
User Offline
Joined: 2nd Nov 2002
Location: United States
Posted: 26th Oct 2003 08:33
Look like the the constants are expanded before the compilation. Just like the #define in C.
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 26th Oct 2003 10:31
constants are just garbage!
you can even do

#constant X = a * b

and change the a and b in your programm and X changes too ... constant does just not work

Dell Inspiron 8200,P4-M 1,7ghz, GF4 440go (45.23 - DX9b), 1GB RAM
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 26th Oct 2003 11:46
a #constant is just that... "constant"... if you set it up like this

x will always be 100... but if you set it up like this

x will always be a*b no matter what a or b is...

a #constant does not have to be ONE number/string... think of it as more of a constant expression... like above x always equals a*b!

==Main Computer==
Athlon XP 3000+, 1024mb, Radeon 9800 Pro 128mb 8xAGP, XP Pro
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 26th Oct 2003 16:48
you don't understand the use of constants don't you?

constants are replaced on compilation with the value they have. afterwards the constants name doesn't exist anymore ... thats the way constants are defined in programming, the way they have to work ... everything else is just a variable

Dell Inspiron 8200,P4-M 1,7ghz, GF4 440go (45.23 - DX9b), 1GB RAM
empty
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Oct 2003 16:59
As mentioned above constants in DBpro are similar to define in C. The "content" of a constant is inserted wherever the constant appears in the source.

I awoke in a fever. The bedclothes were all soaked in sweat.
She said "You've been having a nightmare and it's not over yet"
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 26th Oct 2003 19:13
i have to go with 'empty' on this one simply run this simple test

you are looking at a constant as a number that can never change... a constant is an expression... if that espression says its always ONE number then that is what it is... if that expression says its the SUM of numbers... then that is what it is...

as the example here... x has a different numerical value everytime... but x NEVER changes... it is ALWAYS a+b

yes it is replaced at compile... but not with the value they have... it is replaced by the expression... as in the example 'x' is replaced with 'a+b'

==Main Computer==
Athlon XP 3000+, 1024mb, Radeon 9800 Pro 128mb 8xAGP, XP Pro
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Oct 2003 19:21
It's just text replacement - you are basically saying 'replace this text with this other text'
whome
23
Years of Service
User Offline
Joined: 24th Feb 2003
Location:
Posted: 26th Oct 2003 19:52
Name '#Constant' seems to be a bit misleading compared to a traditional programming languages. #define/#macro would describe it better.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 26th Oct 2003 21:21
#Constant is the wrong term for it. #Constant in every other language means a variable which does not change its value. In DBPro it just means "replace text".

Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 27th Oct 2003 00:57
which just mean use variable because its the same

Dell Inspiron 8200,P4-M 1,7ghz, GF4 440go (45.23 - DX9b), 1GB RAM
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 27th Oct 2003 01:33
it could be helpful if you have a complex expression... lets say like 'x=(2*c)+PlayerMove+((a/b)-0.0345)'... if you have the need for this on numerous occastions... instead of typing all this everytime you need it... you can simply type in 'x'... and bam... done!

yes it may have been named weird... but you may be able to use it to your advantage...

i personally think the name is perfect... not saying a constant value... but a constant expression

==Main Computer==
Athlon XP 3000+, 1024mb, Radeon 9800 Pro 128mb 8xAGP, XP Pro
empty
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 27th Oct 2003 02:07 Edited at: 27th Oct 2003 02:07
Quote: "which just mean use variable because its the same"

Well, but that's because the DBpro compiler doesn't seem to evaluate constant expressions. It would make a difference if it did.
Cause:

would be faster than

even with the current implementation of #constant

I awoke in a fever. The bedclothes were all soaked in sweat.
She said "You've been having a nightmare and it's not over yet"
Surreal Studio IanG
22
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Cyberspace...I think
Posted: 27th Oct 2003 14:17
can someone explain this in newbe speak please
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 27th Oct 2003 16:06
#constant... is simple... name doesnt fit all that well... be here is what it does

#constant x=100
#constant y$="200"
#constant z=a+b

here are three examples, (in big-bird terms) these lines tell DarkBASIC when you run your program, to replace the variable with the value... take the examples above... where ever there is a 'x' variable, DB puts in '100'... where 'y$' is, replaced with the string '200'... and z is replaced with the expression of 'a+b'...

in actuallity #constant only replaces the variable with its expression... (depending on code, a #constant variable could change)

==Main Computer==
Athlon XP 3000+, 1024mb, Radeon 9800 Pro 128mb 8xAGP, XP Pro

Login to post a reply

Server time is: 2026-07-26 16:04:17
Your offset time is: 2026-07-26 16:04:17