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.

Newcomers DBPro Corner / Stupid question with Constants

Author
Message
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 24th May 2009 09:44 Edited at: 24th May 2009 09:51
Hi all, little question about constants, this code won't let me compile!



it says "Compilation Failed (Syntax Errors)" when i try to. do you need to place constants on the top of your code or something? i looked all over the forums but i can;t find the answer...

EDIT: oops sorry, i changed the name from Left to LeftBorder, now it works... :S

Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 24th May 2009 11:30
Yep, cause LEFT is a reserved keyword, being the name of a built in command. ^_^

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th May 2009 16:09 Edited at: 24th May 2009 16:10
There are a couple of things you need to know about constants so that you can use them correctly.

They simply replace text in your source code, they do not pre-calculate or do anything clever at all. Because of this you can get unintended side-effects.

Before you run this code, see if you can predict what value will be printed:


If you said 50, then you've just hit the problem, because the answer is actually 35.

MyConstant*2 ==> x+10*2 ==> x + 20 ==> 35

Fix it by wrapping the replacement text in brackets:


MyConstant*2 ==> (x+10)*2 ==> (15+10)*2 ==> 25*2 ==>50

[edit]Actually, a better and clearer way to do what your original constants do, is to not use constants and use functions instead - your constants aren't really constants.

bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 24th May 2009 17:11
i know, thanks for explanation adn help!

Login to post a reply

Server time is: 2024-11-24 06:33:42
Your offset time is: 2024-11-24 06:33:42