Home All Groups Group Topic Archive Search About

Session("passed") = Session("passed") + 1 error

Author
14 Apr 2005 6:50 PM
dee
Hi
My code complies the following line:
    Session("passed") = 1
but puts wiggly error line under the second  Session("passed") in the
following expression:
    Session("passed") = Session("passed") + 1
Why?
Thanks
Dee.


Session("passed") = Session("passed") + 1

Session("passed") = Session("passed") + 1

Author
14 Apr 2005 8:19 PM
Juan T. Llibre
Because Session("passed") is a string.
Try casting to Int, and then adding 1 to it.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Show quoteHide quote
"dee" <dee@home> wrote in message
news:uOysysSQFHA.164@TK2MSFTNGP12.phx.gbl...
> Hi
> My code complies the following line:
>    Session("passed") = 1
> but puts wiggly error line under the second  Session("passed") in the
> following expression:
>    Session("passed") = Session("passed") + 1
> Why?
> Thanks
> Dee.
>
>
> Session("passed") = Session("passed") + 1
>
> Session("passed") = Session("passed") + 1
>
>
Are all your drivers up to date? click for free checkup

Author
14 Apr 2005 8:42 PM
dee
Thanks Juan :)


Show quoteHide quote
"Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
news:%23Sm1L9SQFHA.3144@tk2msftngp13.phx.gbl...
> Because Session("passed") is a string.
> Try casting to Int, and then adding 1 to it.
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Español
> Ven, y hablemos de ASP.NET...
> ======================
>
> "dee" <dee@home> wrote in message
> news:uOysysSQFHA.164@TK2MSFTNGP12.phx.gbl...
>> Hi
>> My code complies the following line:
>>    Session("passed") = 1
>> but puts wiggly error line under the second  Session("passed") in the
>> following expression:
>>    Session("passed") = Session("passed") + 1
>> Why?
>> Thanks
>> Dee.
>>
>>
>> Session("passed") = Session("passed") + 1
>>
>> Session("passed") = Session("passed") + 1
>>
>>
>
>
Author
15 Apr 2005 8:50 AM
Hans Kesting
Juan T. Llibre wrote:
> Because Session("passed") is a string.
> Try casting to Int, and then adding 1 to it.
>
>

Session("whatever") is not a string, it's an "object".
You can't cast a string to an int (you have to "parse" it),
but you can cast an object to an int (if it really *is* an int).
So your solution *does* work...

--
Hans Kesting
Author
15 Apr 2005 9:56 AM
Juan T. Llibre
Hello, Hans.

While the Session object is an object ( of course ),
its *content* can be a string, as in this particular case
....where the 1 in Session("passed") = 1 is a string, not an object.

This works, for example :

Session("passed") = 1
Dim yNumber as String = Session("passed")
Dim jNumber as Integer = Int32.Parse(yNumber)
Dim wNumber as Integer = jNumber + jNumber
lblMessage.Text = wNumber.ToString()

You're right about the use of "casting", though.
That was a bit sloppy on my part.

I should have used "Convert.ToInt32" or "Parse".

Int32.Parse() is what Convert.ToInt32() calls, anyway, isn't it ?




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Show quoteHide quote
"Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
news:uNKGggZQFHA.2384@tk2msftngp13.phx.gbl...
> Juan T. Llibre wrote:
>> Because Session("passed") is a string.
>> Try casting to Int, and then adding 1 to it.
>>
>>
>
> Session("whatever") is not a string, it's an "object".
> You can't cast a string to an int (you have to "parse" it),
> but you can cast an object to an int (if it really *is* an int).
> So your solution *does* work...
>
> --
> Hans Kesting
Author
15 Apr 2005 10:16 AM
Joseph Byrns
Actually I think you'll find it's an int32 not a string, if you do:

Session("test") = 1

Dim a As String = Session("test").GetType.ToString



You'll see that a is System.Int32


Show quoteHide quote
"Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
news:eCJZsFaQFHA.508@TK2MSFTNGP12.phx.gbl...
> Hello, Hans.
>
> While the Session object is an object ( of course ),
> its *content* can be a string, as in this particular case
> ...where the 1 in Session("passed") = 1 is a string, not an object.
>
> This works, for example :
>
> Session("passed") = 1
> Dim yNumber as String = Session("passed")
> Dim jNumber as Integer = Int32.Parse(yNumber)
> Dim wNumber as Integer = jNumber + jNumber
> lblMessage.Text = wNumber.ToString()
>
> You're right about the use of "casting", though.
> That was a bit sloppy on my part.
>
> I should have used "Convert.ToInt32" or "Parse".
>
> Int32.Parse() is what Convert.ToInt32() calls, anyway, isn't it ?
>
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Español
> Ven, y hablemos de ASP.NET...
> ======================
>
> "Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
> news:uNKGggZQFHA.2384@tk2msftngp13.phx.gbl...
>> Juan T. Llibre wrote:
>>> Because Session("passed") is a string.
>>> Try casting to Int, and then adding 1 to it.
>>>
>>>
>>
>> Session("whatever") is not a string, it's an "object".
>> You can't cast a string to an int (you have to "parse" it),
>> but you can cast an object to an int (if it really *is* an int).
>> So your solution *does* work...
>>
>> --
>> Hans Kesting
>
>
Author
15 Apr 2005 10:30 AM
Juan T. Llibre
Cool...

And Session("passed") = "1" 's type is ... ?

;-)

Question for you :

How does Session("passed") = 1
get converted from Int32 to String in
Dim yNumber as String = Session("passed")

Shouldn't that cause an "incorrect type" error ?



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Show quoteHide quote
"Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> wrote in message
news:ehObERaQFHA.3120@TK2MSFTNGP10.phx.gbl...
> Actually I think you'll find it's an int32 not a string, if you do:
>
> Session("test") = 1
>
> Dim a As String = Session("test").GetType.ToString
>
> You'll see that a is System.Int32


> "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
> news:eCJZsFaQFHA.508@TK2MSFTNGP12.phx.gbl...
>> Hello, Hans.
>>
>> While the Session object is an object ( of course ),
>> its *content* can be a string, as in this particular case
>> ...where the 1 in Session("passed") = 1 is a string, not an object.
>>
>> This works, for example :
>>
>> Session("passed") = 1
>> Dim yNumber as String = Session("passed")
>> Dim jNumber as Integer = Int32.Parse(yNumber)
>> Dim wNumber as Integer = jNumber + jNumber
>> lblMessage.Text = wNumber.ToString()
>>
>> You're right about the use of "casting", though.
>> That was a bit sloppy on my part.
>>
>> I should have used "Convert.ToInt32" or "Parse".
>>
>> Int32.Parse() is what Convert.ToInt32() calls, anyway, isn't it ?
>>
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> http://asp.net.do/foros/
>> Foros de ASP.NET en Español
>> Ven, y hablemos de ASP.NET...
>> ======================
>>
>> "Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
>> news:uNKGggZQFHA.2384@tk2msftngp13.phx.gbl...
>>> Juan T. Llibre wrote:
>>>> Because Session("passed") is a string.
>>>> Try casting to Int, and then adding 1 to it.
>>>>
>>>>
>>>
>>> Session("whatever") is not a string, it's an "object".
>>> You can't cast a string to an int (you have to "parse" it),
>>> but you can cast an object to an int (if it really *is* an int).
>>> So your solution *does* work...
>>>
>>> --
>>> Hans Kesting
>>
>>
>
>
Author
15 Apr 2005 10:34 AM
Joseph Byrns
Then it's a string, but there are no quotes in the example provided above.

Show quoteHide quote
"Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
news:ea5ajYaQFHA.612@TK2MSFTNGP14.phx.gbl...
> Cool...
>
> And Session("passed") = "1" 's type is ... ?
>
> ;-)
>
> Question for you :
>
> How does Session("passed") = 1
> get converted from Int32 to String in
> Dim yNumber as String = Session("passed")
>
> Shouldn't that cause an "incorrect type" error ?
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Español
> Ven, y hablemos de ASP.NET...
> ======================
>
> "Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> wrote in message
> news:ehObERaQFHA.3120@TK2MSFTNGP10.phx.gbl...
>> Actually I think you'll find it's an int32 not a string, if you do:
>>
>> Session("test") = 1
>>
>> Dim a As String = Session("test").GetType.ToString
>>
>> You'll see that a is System.Int32
>
>
>> "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
>> news:eCJZsFaQFHA.508@TK2MSFTNGP12.phx.gbl...
>>> Hello, Hans.
>>>
>>> While the Session object is an object ( of course ),
>>> its *content* can be a string, as in this particular case
>>> ...where the 1 in Session("passed") = 1 is a string, not an object.
>>>
>>> This works, for example :
>>>
>>> Session("passed") = 1
>>> Dim yNumber as String = Session("passed")
>>> Dim jNumber as Integer = Int32.Parse(yNumber)
>>> Dim wNumber as Integer = jNumber + jNumber
>>> lblMessage.Text = wNumber.ToString()
>>>
>>> You're right about the use of "casting", though.
>>> That was a bit sloppy on my part.
>>>
>>> I should have used "Convert.ToInt32" or "Parse".
>>>
>>> Int32.Parse() is what Convert.ToInt32() calls, anyway, isn't it ?
>>>
>>>
>>>
>>>
>>> Juan T. Llibre
>>> ASP.NET MVP
>>> http://asp.net.do/foros/
>>> Foros de ASP.NET en Español
>>> Ven, y hablemos de ASP.NET...
>>> ======================
>>>
>>> "Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
>>> news:uNKGggZQFHA.2384@tk2msftngp13.phx.gbl...
>>>> Juan T. Llibre wrote:
>>>>> Because Session("passed") is a string.
>>>>> Try casting to Int, and then adding 1 to it.
>>>>>
>>>>>
>>>>
>>>> Session("whatever") is not a string, it's an "object".
>>>> You can't cast a string to an int (you have to "parse" it),
>>>> but you can cast an object to an int (if it really *is* an int).
>>>> So your solution *does* work...
>>>>
>>>> --
>>>> Hans Kesting
>>>
>>>
>>
>>
>
>
Author
15 Apr 2005 10:42 AM
Juan T. Llibre
re:
> Then it's a string, but there are no quotes in the example provided above.

I know...

Do you have any ideas about the question I asked ?

How does Session("passed") = 1
get converted from Int32 to String in
Dim yNumber as String = Session("passed")

Shouldn't that cause an "incorrect type" error ?




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

Show quoteHide quote
"Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> wrote in message
news:eF1XqaaQFHA.3596@TK2MSFTNGP15.phx.gbl...
> Then it's a string, but there are no quotes in the example provided above.
>
> "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
> news:ea5ajYaQFHA.612@TK2MSFTNGP14.phx.gbl...
>> Cool...
>>
>> And Session("passed") = "1" 's type is ... ?
>>
>> ;-)
>>
>> Question for you :
>>
>> How does Session("passed") = 1
>> get converted from Int32 to String in
>> Dim yNumber as String = Session("passed")
>>
>> Shouldn't that cause an "incorrect type" error ?
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> http://asp.net.do/foros/
>> Foros de ASP.NET en Español
>> Ven, y hablemos de ASP.NET...
>> ======================
>>
>> "Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> wrote in message
>> news:ehObERaQFHA.3120@TK2MSFTNGP10.phx.gbl...
>>> Actually I think you'll find it's an int32 not a string, if you do:
>>>
>>> Session("test") = 1
>>>
>>> Dim a As String = Session("test").GetType.ToString
>>>
>>> You'll see that a is System.Int32
>>
>>
>>> "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
>>> news:eCJZsFaQFHA.508@TK2MSFTNGP12.phx.gbl...
>>>> Hello, Hans.
>>>>
>>>> While the Session object is an object ( of course ),
>>>> its *content* can be a string, as in this particular case
>>>> ...where the 1 in Session("passed") = 1 is a string, not an object.
>>>>
>>>> This works, for example :
>>>>
>>>> Session("passed") = 1
>>>> Dim yNumber as String = Session("passed")
>>>> Dim jNumber as Integer = Int32.Parse(yNumber)
>>>> Dim wNumber as Integer = jNumber + jNumber
>>>> lblMessage.Text = wNumber.ToString()
>>>>
>>>> You're right about the use of "casting", though.
>>>> That was a bit sloppy on my part.
>>>>
>>>> I should have used "Convert.ToInt32" or "Parse".
>>>>
>>>> Int32.Parse() is what Convert.ToInt32() calls, anyway, isn't it ?
>>>>
>>>>
>>>>
>>>>
>>>> Juan T. Llibre
>>>> ASP.NET MVP
>>>> http://asp.net.do/foros/
>>>> Foros de ASP.NET en Español
>>>> Ven, y hablemos de ASP.NET...
>>>> ======================
>>>>
>>>> "Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
>>>> news:uNKGggZQFHA.2384@tk2msftngp13.phx.gbl...
>>>>> Juan T. Llibre wrote:
>>>>>> Because Session("passed") is a string.
>>>>>> Try casting to Int, and then adding 1 to it.
>>>>>>
>>>>>>
>>>>>
>>>>> Session("whatever") is not a string, it's an "object".
>>>>> You can't cast a string to an int (you have to "parse" it),
>>>>> but you can cast an object to an int (if it really *is* an int).
>>>>> So your solution *does* work...
>>>>>
>>>>> --
>>>>> Hans Kesting
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
15 Apr 2005 10:47 AM
Joseph Byrns
Hmm, I think .net is just being friendly and automatically casting the int32
to a string for you.  That's my guess anyway.

you get the same thing if you do:

Dim a As Int32 = 1

Dim b As String = a




Show quoteHide quote
"Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
news:u0rLafaQFHA.3596@TK2MSFTNGP15.phx.gbl...
> re:
>> Then it's a string, but there are no quotes in the example provided
>> above.
>
> I know...
>
> Do you have any ideas about the question I asked ?
>
> How does Session("passed") = 1
> get converted from Int32 to String in
> Dim yNumber as String = Session("passed")
>
> Shouldn't that cause an "incorrect type" error ?
>
>
>
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Español
> Ven, y hablemos de ASP.NET...
> ======================
>
> "Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> wrote in message
> news:eF1XqaaQFHA.3596@TK2MSFTNGP15.phx.gbl...
>> Then it's a string, but there are no quotes in the example provided
>> above.
>>
>> "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
>> news:ea5ajYaQFHA.612@TK2MSFTNGP14.phx.gbl...
>>> Cool...
>>>
>>> And Session("passed") = "1" 's type is ... ?
>>>
>>> ;-)
>>>
>>> Question for you :
>>>
>>> How does Session("passed") = 1
>>> get converted from Int32 to String in
>>> Dim yNumber as String = Session("passed")
>>>
>>> Shouldn't that cause an "incorrect type" error ?
>>>
>>>
>>>
>>> Juan T. Llibre
>>> ASP.NET MVP
>>> http://asp.net.do/foros/
>>> Foros de ASP.NET en Español
>>> Ven, y hablemos de ASP.NET...
>>> ======================
>>>
>>> "Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> wrote in message
>>> news:ehObERaQFHA.3120@TK2MSFTNGP10.phx.gbl...
>>>> Actually I think you'll find it's an int32 not a string, if you do:
>>>>
>>>> Session("test") = 1
>>>>
>>>> Dim a As String = Session("test").GetType.ToString
>>>>
>>>> You'll see that a is System.Int32
>>>
>>>
>>>> "Juan T. Llibre" <nomailrepl***@nowhere.com> wrote in message
>>>> news:eCJZsFaQFHA.508@TK2MSFTNGP12.phx.gbl...
>>>>> Hello, Hans.
>>>>>
>>>>> While the Session object is an object ( of course ),
>>>>> its *content* can be a string, as in this particular case
>>>>> ...where the 1 in Session("passed") = 1 is a string, not an object.
>>>>>
>>>>> This works, for example :
>>>>>
>>>>> Session("passed") = 1
>>>>> Dim yNumber as String = Session("passed")
>>>>> Dim jNumber as Integer = Int32.Parse(yNumber)
>>>>> Dim wNumber as Integer = jNumber + jNumber
>>>>> lblMessage.Text = wNumber.ToString()
>>>>>
>>>>> You're right about the use of "casting", though.
>>>>> That was a bit sloppy on my part.
>>>>>
>>>>> I should have used "Convert.ToInt32" or "Parse".
>>>>>
>>>>> Int32.Parse() is what Convert.ToInt32() calls, anyway, isn't it ?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Juan T. Llibre
>>>>> ASP.NET MVP
>>>>> http://asp.net.do/foros/
>>>>> Foros de ASP.NET en Español
>>>>> Ven, y hablemos de ASP.NET...
>>>>> ======================
>>>>>
>>>>> "Hans Kesting" <news.2.hansdk@spamgourmet.com> wrote in message
>>>>> news:uNKGggZQFHA.2384@tk2msftngp13.phx.gbl...
>>>>>> Juan T. Llibre wrote:
>>>>>>> Because Session("passed") is a string.
>>>>>>> Try casting to Int, and then adding 1 to it.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> Session("whatever") is not a string, it's an "object".
>>>>>> You can't cast a string to an int (you have to "parse" it),
>>>>>> but you can cast an object to an int (if it really *is* an int).
>>>>>> So your solution *does* work...
>>>>>>
>>>>>> --
>>>>>> Hans Kesting
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

Bookmark and Share