Forum Moderators: phranque

Message Too Old, No Replies

Dumb vbscript question

Help ME!

         

Krapulator

11:57 pm on Nov 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I have a problem. The following script returns the value "2" regardless of the values of the variables.
Why O Why?

number_nights = (rates.Fields.Item("sNumberNights").Value)
day_diff = DateDiff("d", arrival, depart)

if (Cstr(number_nights)) < (Cstr(date_diff)) then
action = 1
elseif (Cstr(number_nights)) > (Cstr(date_diff)) then
action = 2
else
action = 3
end if
response.write action

korkus2000

12:16 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try CInt instead of CStr. I am guessing that the < and > values of your strings are coming up with option 2.

Krapulator

12:35 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nope, still get 2 every time with CInt

oilman

12:40 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



shouldn't you be useing day_diff in the comparison expressions instead of date_diff?

Krapulator

12:46 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



day_diff is just the name I've given the variable. Its value comes from the date_diff function at the top. However I have tried the same script without the variables, just dropping the date_diff function and recordset varible straoght into the comparison, but the result is still 2 doing it this way

jatar_k

12:48 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



oil was referring to this

day_diff = DateDiff("d", arrival, depart)

if (Cstr(number_nights)) < (Cstr(date_diff)) then

they don't match, if that is what you are trying to compare

oilman

12:48 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



right - I just thot maybe that was the variable you were wanting to compare and just put the wrong name in - I do it all the time. Just a thot :)

edit: what jatar said :)

Krapulator

1:02 am on Nov 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bloody Hell.

(Bangs head against wall - kicks self in arse - mutters profanities that would make a biker blush).

Im a bloody idiot.

It was right in front of my face.

Thanks guys - you just made my christmas card list!

shady

1:32 am on Nov 22, 2002 (gmt 0)

10+ Year Member



It may be a good idea (assuming it is available in vbscript) to use "option explicit" - that way the scripts will fall over with an error rather than treating undefined variables as zero.

Makes "finger trouble" stand out instead of giving you sleepless nights!