#134172 - 2005-02-20 09:24 AM
HELP ! Strings and math is like me and clean office desks....
|
Bjoern
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
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
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
|
|
|
|
#134177 - 2005-02-21 06:40 AM
Re: HELP ! Strings and math is like me and clean office desks....
|
ShaneEP
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
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|