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 / Need help with As Float and #

Author
Message
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 15th Nov 2003 22:23
What is the difference between using a variable with the real number designator i.e.

MyNumber#=0.005

And

Dim MyNumber As Float
MyNumber=0.005

Does that work? It doesn't give me an error. I know that this is in the help but I don't think the part about real numbers and floats is that clear.

With all things in life - try hard. Success does not come with meeting the minimum requirements.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 15th Nov 2003 23:40
I never understood the help file either. i just use

fltMyVar as Float
intMyVar as Integer
strMyVar as String

I never use the silly $,# signs. Oh and don't forget a global string is a G-string

Global g_StrMyVar as string

-RUST-
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 17th Nov 2003 00:00
no prob- I didn't realize that we were discussing VB, silly me I thought we were disussing DBP

The $ symbol in VB sets the function return (from mid left right etc)as a true String as opposed to a Variant which uses 16bytes of memomry.

.NET did away with variant! Thank god.

-RUST-
Black Hydra
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 17th Nov 2003 00:49
I guess it means, if not declared, a variable is an integer. putting a $ or # after is like shortcutting a AS STRING or AS FLOAT
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 17th Nov 2003 01:44
yes that's what it means. It's an old throw -back to procedural basic. Is ok I guess, i choose not to use it however.

@DBZ - LOL I have been around a while and I know you are eccentric!

-RUST-
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 17th Nov 2003 03:09
No I wasn't asking about VB. VB's help file is far more helpful.

My confusion lies in DBP. Since we're on the subjet though is there anyway to decare Option Explicit in DBP?

With all things in life - try hard. Success does not come with meeting the minimum requirements.
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 17th Nov 2003 03:12
And how is it that there is no "Global" command in DBP's helpfile yet it works? Are there alot of undocumented commands?

With all things in life - try hard. Success does not come with meeting the minimum requirements.
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 17th Nov 2003 03:18 Edited at: 17th Nov 2003 03:19
As a matter of fact with a little testing I discovered that all the following statements work in setting up a float variable. I'm sure it works for all types. I have no Idea why you would use one method over another.

Dim A(1) as Float
A as Float
Global AG as Float
A1# as Float

AG=0.005
A=0.005
A#=0.005
A(1)=0.005

Print AG
Print A
Print A#
Print A(1)

Wait Key

With all things in life - try hard. Success does not come with meeting the minimum requirements.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 17th Nov 2003 03:41
intersting. That is one of the more "loose" features of dbp that I actually don't like. Coming from vb, which is strongly typed, and with my default usage of Option Explicit & Option Strict, nothing is left to chance, or left to what the compiler thinks a variable should be. But that's just me.

vb:
Dim CattleRustler as AnalRetentiveParanoidProgrammer
With CattleRustler
.smack
.smack
.smack
End With

-RUST-
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 17th Nov 2003 03:53
What is Option Strict? I'm not strong in either although I can get the job done...most of the time. Heheh, good example.

With all things in life - try hard. Success does not come with meeting the minimum requirements.
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 17th Nov 2003 03:58
And another thing. Why are all my floats not exact? If I set a variable to equal 0.005, why does it return 0.004932420? I understand that there are memory locations involved and if you don't decare them in other languages you can get undesired results but here I am decaring them and I would have to round it to make it exact.

With all things in life - try hard. Success does not come with meeting the minimum requirements.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 17th Nov 2003 06:15 Edited at: 17th Nov 2003 06:17
sorry, i never answered your original question: In DBP there is no such thing as Option Explicit - and it is very much needed IMHO! One var spelling mistake and whammo-you have a new variable -yuck

As far as Option Strict, in VB it means no implicit type conversion can take place, the type conversion has to be explicitly written in code. So you can't just mix and match nums and strings all willy nilly and get a result - a dbp example would be the PRINT statement. you could say:

intMyVar as Integer=10
print intMyVar

but an option strict setting would disallow this as the conversion needs to be explicit not implicit (implied) so the print line would need to read:

print str$(intMyVar)
In other words PRINT the return value of the STR$ function which is a string.

Neither O-Explicit or O-Strict is available in DBP but from my experience in VB, and especially vb.net, it would be a welcomed addition - IMHO



-RUST-
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 18th Nov 2003 20:42
While there is no option explicit (an often requested feature), there is a work around that was told to me. You can use user defined types to force variable declaration.

type variableDeclaration
blonde as string
endType

s as variableDeclaration

Only s.blonde will work as any mispellings are caught.
--
TAZ
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 18th Nov 2003 20:44
pah!



-RUST-
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 19th Nov 2003 04:56
Ptah? Cool diety from my old 2nd edition AD&D days.

While the UDT hack is a little clumsy, if you're using Hungarian notation, if is trival to add the period to your variables. Just create a UDT for all your integers, strings, and floats.
--
TAZ
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Nov 2003 06:02
i remember ptah
he was a bald egyptian looking guy

-RUST-

Login to post a reply

Server time is: 2024-11-25 17:22:50
Your offset time is: 2024-11-25 17:22:50