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 / How to let this check if its equal?(DBP)

Author
Message
Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 29th Oct 2006 14:59
OK,i want to check if these two strings,variables have the same number:

Inp$ should be the same number as Num#

but this doesnt check it good:



i thought "=" ment Equals!

Whats wrong with this?

My arrival shocked some people maybe...but i dont seem to care anyway...behold my mights!
-Prince Of Darkness
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 29th Oct 2006 15:42
= does mean =, but if num# is a float it may never work out =

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 29th Oct 2006 16:34
so Num# must be Num$?

My arrival shocked some people maybe...but i dont seem to care anyway...behold my mights!
-Prince Of Darkness
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 29th Oct 2006 18:00 Edited at: 29th Oct 2006 18:03
In a nutshell

Quote: "
String $ :letters and numbers and symbols
Integer :whole number
floating point :decimal place number

examples

rem comparing two integers
NumA = 1 : NumB = 3
if NumA = NumB then print "same amount" else print "different amount"


rem comparing two strings
Name1$= "fred" : Name2$ = "fred"
if Name1$ = Name2$ then print "same name" else print "different names"


rem comparing two floats
NumA# = 1.55 : NumB# = 3.55
if NumA# = NumB# then print "same amount" else print "different amount"


rem comparing a string to an integer, by converting integar to a string at conversion
Name$ = "1" : Num = 1
if Name$ = STR$(Num) then print "same " else print "different "
"

and you can mix different combinations if you convert one to another etc..

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 29th Oct 2006 20:32
Thanks indi,ill keep that list on my desktop!

My arrival shocked some people maybe...but i dont seem to care anyway...behold my mights!
-Prince Of Darkness
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 29th Oct 2006 21:00
actually what I was trying to say was your string might be 5.25 for example but your float might be 5.253456789. When you do the compare it wont be equal, one string will be "5.25" the other "5.253456789". Even if you round or trunc digits it might not always work because floats are floats. If you were comparing string and integer you might have more reliable results but integers dont carry fractional part. If the numbers you need to compare to strings are whole (no fractions) then dont use float (#) use integers

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 29th Oct 2006 21:07
its used in a Number guessing thing,and well.now it tells me its always wrong!(While for de-bugging,it gives a messagebox telling the right number...)

ill be looking further into this codes,and i should keep what the strings mean in my head...

My arrival shocked some people maybe...but i dont seem to care anyway...behold my mights!
-Prince Of Darkness
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 29th Oct 2006 21:10
right ok. if the number guessing game only uses whole numbers like 1,2,3... etc then use integer for the current num# variable

iNum As Integer
sNum As String

etc

Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 30th Oct 2006 02:29
I never did get that: why are floats off sometimes by a bit? Like past the decimal places you give it. I can't remember the specific example, but there was one time I used a float and printed it and it printed it wierd, like I defined it as 4.5 and it printed something like 4.500140210112

Pirates of Port Royale
Live the life of a pirate.
Crit
18
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 30th Oct 2006 18:27
Floats are stored in binary. The result is the decimal portion of a number has to be represented as a sum of fractions with the denominator being a power of 2.

So imagine if you only had 4 bits to try to represent the number 0.95
The closest you could come would be 1/2 + 1/4 + 1/8 + 1/16 = .09375

Of course dark basic uses a lot more than 4 bits, but you get the idea.

CHESS ENCOUNTER
Demo
WIP

Login to post a reply

Server time is: 2024-11-27 03:52:37
Your offset time is: 2024-11-27 03:52:37