Page 1 of 1 1
Topic Options
#119274 - 2004-05-10 01:24 PM counting these values
Trackz Offline
Fresh Scripter

Registered: 2004-03-18
Posts: 37
Loc: Rotterdam, The Netherlands
Something goes wrong over here
I retrieve the current hour with this code

$hour = LTrim(SubStr(@TIME, 1, 2))
$offset = 2

The $offset is used to store a value, to be added to the $hour

So, the $hour now returns: 13
I like to count the $offset to $hour

When I use $time=$hour+$offset, I expected it to return 15 (in stead of what I now get: 132)

What am I doing wrong here?



Top
#119275 - 2004-05-10 01:34 PM Re: counting these values
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
@HOUR is a VarTypeName = String. So, adding to it will append your integer to the string. You must convert the string value to an integer...

Code:

$time = Val($hour) + $offset



Top
#119276 - 2004-05-10 02:01 PM Re: counting these values
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
yes... but I would do it like this.

$hour = val(LTrim(SubStr(@TIME, 1, 2)))

Which of course does the same thing, but in my mind, I expect hour to be a number, so I convert it first.

6 of one...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#119277 - 2004-05-10 02:14 PM Re: counting these values
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
true, but why LTrim ?
_________________________



Top
#119278 - 2004-05-10 03:43 PM Re: counting these values
Trackz Offline
Fresh Scripter

Registered: 2004-03-18
Posts: 37
Loc: Rotterdam, The Netherlands
Thanx. works fine
Top
Page 1 of 1 1


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

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.085 seconds in which 0.061 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