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 / help with declaring a vriable as a real

Author
Message
zaitsev57
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: Cleveland
Posted: 15th Oct 2005 00:39
Ugh, ok i tried posting about five minutes ago and it didnt work? Well long story short, i got DBpro 2 years ago, got discouraged and put it aside. Am now taking a visualbasic class, got renewed interest and just restarting today.

Trying to keep good (visualbasic) habit and keeping my code clean and easy to read to myself... heres my question.

how can i declare a variable as a real number?
ex. -> mydata as real
instead of mydata#

it works with -> mydata as integer and-> mydata as string
but not with real?
I want to stay away from those symbols($,#) they look messy and confusing to me. anywho thanks for helping! cyas
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Oct 2005 02:49
Quote: "I want to stay away from those symbols($,#) they look messy and confusing to me. anywho thanks for helping! cyas "


But once you learn that when you see $ you know it's a string and once you see # you know it's real number. Why is it so hard for you?

Maybe you should make a little program to train yourself to instantly think $=string and #=real. You'll have an easier time looking at other peoples code that aren't confused by the symbols.
zaitsev57
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: Cleveland
Posted: 15th Oct 2005 02:50
ok thnx, so reals are floats. another Q.

i put in
and it prints 4.324990125....
i mean, i know its close to 4.325 , but i wanna know why its doing that
just trying to have a good programming foundation here
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 15th Oct 2005 03:10
What Grog Grueslayer says is true. However, if you feel that it looks messy (I sometimes do, I'm taking a C++ class) then what you need to do is do what Moderator said. I suggest you train yourself to not see the symbols as messy though because most code snippets and source code uses those.

I R tEh Antid0te! ROOOAAAR!
zaitsev57
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: Cleveland
Posted: 15th Oct 2005 06:21
Yea i guess you guys are right i mean, i guess its because im used to visualbasic a little. but anywho, my last question still stands, about the computer making 4.325 into a really close but not quite that number.

Also any good direction to point me in my DB learning experience would be nice and appreciated. I startin with the tutorial in the manual, then moving off to stuff i find in the forums (pong tut. and such)

Thanks and take care!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 15th Oct 2005 15:42
Imho $ and # symbols shouldnt be used. Try a form of notation when naming your variables, for easy type identification.

examples:

sPlayerName as String
iSecsElapsed as Integer
fPlayerX as Float
dSomeVar as Dword

etc
hope that helps

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Oct 2005 21:41
Quote: "Imho $ and # symbols shouldnt be used. Try a form of notation when naming your variables, for easy type identification.
"


To me seeing $'s and #'s is the easiest for type identification. Especially when you're looking at line 2000 and can't figure out if "Player" is a string or variable because line 10 is where "Player" is defined. If you see "Player$" you know instantly that it's a string. Easy identification is what you want when you look at your code months or years later. Of course your system appears to work good for you.
zaitsev57
19
Years of Service
User Offline
Joined: 14th Oct 2005
Location: Cleveland
Posted: 15th Oct 2005 22:38
Yea. I was goin with cattlerustler's idea in the first place, just didnt know reals=floats . I dunno, ill see which works better for me after some messing around with programming.

Anywho. my second Q still stands. the 4.325 one.

thnx for the help guys, and i guess a good discussion about labeling variables has occured also. thnx for it all, cyas
Flip5577
20
Years of Service
User Offline
Joined: 3rd Nov 2004
Location:
Posted: 2nd Jan 2006 09:19
I agree, i have been having the same problem with dark basic, when I make real decimal numbers, Dark Basic Pro makes the value a number very close to the one I wanted but not exactly.

example:

temp# = 60.0
print temp#;

and I recieve
59.999399194

or something of the sort, why does DB do that and how do I fix it?

Larry Charles, Jr.

Login to post a reply

Server time is: 2024-11-27 14:27:41
Your offset time is: 2024-11-27 14:27:41