Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session("passed") = Session("passed") + 1 error

Reply
Thread Tools

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

 
 
dee
Guest
Posts: n/a
 
      04-14-2005
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


 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      04-14-2005
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:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
dee
Guest
Posts: n/a
 
      04-14-2005
Thanks Juan


"Juan T. Llibre" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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:(E-Mail Removed)...
>> 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
>>
>>

>
>



 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      04-15-2005
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
 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      04-15-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Joseph Byrns
Guest
Posts: n/a
 
      04-15-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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

>
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      04-15-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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

>>
>>

>
>



 
Reply With Quote
 
Joseph Byrns
Guest
Posts: n/a
 
      04-15-2005
Then it's a string, but there are no quotes in the example provided above.

"Juan T. Llibre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      04-15-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Then it's a string, but there are no quotes in the example provided above.
>
> "Juan T. Llibre" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> 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
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Joseph Byrns
Guest
Posts: n/a
 
      04-15-2005
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




"Juan T. Llibre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Then it's a string, but there are no quotes in the example provided
>> above.
>>
>> "Juan T. Llibre" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> 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" <(E-Mail Removed)> wrote in message
>>>>> news:(E-Mail Removed)...
>>>>>> 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
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments