Page 1 of 1 1
Topic Options
#134172 - 2005-02-20 09:24 AM HELP ! Strings and math is like me and clean office desks....
Bjoern Offline
Fresh Scripter

Registered: 2005-02-20
Posts: 9
Yep... It just doesn't work !!!!
I'm having problems with a simple mathematical operation with data received from an INI-file.

Data I receive from the INI-file goes to $data.
After I received the data, I want it to add by one (+1), and store the new data in $counter.
What I've done is: $counter = $data + 1

Let's say I receive 5 from the INI-file. $data would then naturally be 5, and then starts the problem...
I do the mathematical operation, but $counter does not end up as 6 ! It ends up as 51... WHY !?!?!?!? WHY !?!?!?!?

I want it to do math, not... hmm... that !


Any solutions on this problem, guys ??

Top
#134173 - 2005-02-20 10:07 AM Re: HELP ! Strings and math is like me and clean office desks....
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Hey there. Simple enough to get around. Im assuming the data you are trying to add 1 to is already assigned to a variable, in this example we'll call it $data. There are a few built in kix functions that will make the variable into an integer. Int() for example. If you look at the code below, $counter1 will return 51 to the screen where as $counter2 will return the desired 6 since $data was changed to an integer before the math was performed.

Code:

$data = "5"
$counter1 = $data+1
$counter2 = Int($data)+1

? $counter1
? $counter2
get $



Of course if i didnt put quotes around the 5 to begin with it would already be treated as an integer, so we would have to see you code to say exactly whats goin on. Something like Int() should solve your problem however.

Top
#134174 - 2005-02-20 10:22 AM Re: HELP ! Strings and math is like me and clean office desks....
Bjoern Offline
Fresh Scripter

Registered: 2005-02-20
Posts: 9
Hey ! That worked perfect !!
Thanks a lot, man ! I've rated you 5 ! Clear, quick and helpful answers are exactly what we need around here.

Thanks !

Top
#134175 - 2005-02-20 10:27 AM Re: HELP ! Strings and math is like me and clean office desks....
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Awesome...glad it worked for ya. just let us know if you run into anymore issues. theres almost always someone around here thats more than willing to help.
Top
#134176 - 2005-02-20 02:42 PM Re: HELP ! Strings and math is like me and clean office desks....
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Huh?

Wahts all that code for?

Just add the var to the integer instead of the other way around.

$Data = 1 + ReadProfileString('bla','bla','bla')

If you start with an integer, KiX will convert the rest for you. The inverse is also true.
Code:
Break On
$str = "1"
$int = 1

$strResult = $str + $int
'Result = '+ $strResult + ' is ' + VarTypeName($strResult) ?

$intResult = $int + $str
'Result = '+ $intResult + ' is ' + VarTypeName($intResult) ?


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#134177 - 2005-02-21 06:40 AM Re: HELP ! Strings and math is like me and clean office desks....
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Wahhh...here ya go

ok so yours saves 5 keystrokes with...

$Data = 1 + ReadProfileString('bla','bla','bla')

instead of...

$Data = Int(ReadProfileString('bla','bla','bla')) + 1

I myself would prefer the 2nd just cause its easier to follow, but thats just me.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.053 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org