|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Session("passed") = Session("passed") + 1 errorHi
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 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 > > 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 >> >> > > Juan T. Llibre wrote:
> Because Session("passed") is a string. Session("whatever") is not a string, it's an "object".> Try casting to Int, and then adding 1 to it. > > 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 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 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 > > 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 >> >> > > 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 >>> >>> >> >> > > 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 >>>> >>>> >>> >>> >> >> > > 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 >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >
Other interesting topics
Adding @Assembly references programmatically
FormsAuthentication.SignOut() not working when manually creating a ticket? Custom ToolBoxItem type: Can I develop ASP.NET/C# applications in Microsoft Visual C# .NET Standard 2003? Size vs Width in ASP.net Can't Update of Cookie Posting to a PHP Page Calling the window dialog window Security For Running An Application Launching client side applications |
|||||||||||||||||||||||