tags:

views:

459

answers:

2

Hi,

I have a strange problem where CInt (as well as Convert.ToInt32 or even Val) return -1 for a string "500". Using Gurock's SmartInspect for logging, I've checked all values at runtime (SiAuto... logs something, I'm posting the log below the code). Would appreciate some hlp :)

Thanks

Michael

Si.Auto.Main.LogString("QueryString.q1",GetQueryStringParam("q1","0"))
' is it really "500" as it seems?
SiAuto.Main.LogBool("Is q1 = 500 in query-string?","500"=GetQueryStringParam("q1","0"))
q1 = CInt(GetQueryStringParam("q1","0"))
'don't worry abt that q1a-bit, the first string is just the title...
SiAuto.Main.LogInt("q1a",q1)

q1 = Convert.ToInt32(GetQueryStringParam("q1","0"))
SiAuto.Main.LogInt("q1b",q1)

q1 = val(GetQueryStringParam("q1","0"))
SiAuto.Main.LogInt("q1c",q1)

And here's the log:

QueryString.q1 = "500"
Is q1 = 500 in query-string? = True
q1a = -1
q1b = -1
q1c = -1
+3  A: 

Rather than making repeated calls to GetQueryStringParam() (what are you using, by the way?), store this value in a local string variable. This will make both your code and testing more reliable by eliminating the possibility that your function is behaving in a nondeterministic manner.

In any event, look into int.Parse() or int.TryParse() for your conversions as well, though what you have appears that it SHOULD work.

Edit

If none of that works, my only suggestion would be--and yes, this may actually do something--running the code under another account on your computer, or on another computer altogether. If your windows profile is corrupted you can have issues converting formattable data types to a from a string.

Adam Robinson
Oops, sorry, posted my comment above - #Fail :(Anyway, tried that, did not help.GetQueryStringParam is just a thin cover for Request.GetQueryString to handle default-vals for optional qs-params more easily.
MBaas
See edit above.
Adam Robinson
Adam, I tried to un under another account and have also taken the program to my Win2003-server - same mis-behaviour everywhere :((
MBaas
A: 

Oh, too bad, sorry guys, I found the fault: someone had declared q1 as Boolean :(

MBaas