|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Storing an array to a SessionSession variable. Later, I need to use this array so I am doing the following: Dim eventTypes As String() = DirectCast(Session("EventTypes"), String()) If Date.Today <= closeDate Then If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = Session("JRFee") Else thisFee = Session("PEFee") Else If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = Session("JRFee") Else thisFee = Session("DOSFee") End If I have determined that the values are properly being stored into the initial array. I then assign a session variable to store this array. When I try to use the array in the segment above, I get the error "Object reference not set to an instance of an object - use the "new keyword". Obviously when I dim the eventTypes() something is wrong here. Please help. Thanks for the information. Either a new session is being started, or you are not retrieving the data
using the same session variable name, or something like that. Basically, your variable references nothing after the assignment. Show quoteHide quote "Brad" <B***@discussions.microsoft.com> wrote in message news:45751585-D68E-45B2-AB69-05B9BE41C0F0@microsoft.com... >I am storing an array which contains about a dozen chracter items to a > Session variable. Later, I need to use this array so I am doing the > following: > > Dim eventTypes As String() = DirectCast(Session("EventTypes"), String()) > If Date.Today <= closeDate Then > If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = > Session("JRFee") Else thisFee = Session("PEFee") > Else > If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = > Session("JRFee") Else thisFee = Session("DOSFee") > End If > > I have determined that the values are properly being stored into the > initial > array. I then assign a session variable to store this array. When I try > to > use the array in the segment above, I get the error "Object reference not > set > to an instance of an object - use the "new keyword". > > Obviously when I dim the eventTypes() something is wrong here. Please > help. > > Thanks for the information. If you have the array in the session I would do this:
Dim EventTypes as String() EventTypes = Session("EventTypes") If for some reason that doesn't work just put this line in the middle to try (I know it's nuts but try it) Redim EventTypes(0) Make sure that Date.Today, cblEntries.SelectedIndex and Session("PEFee") etc. all exist. The problem might not be the array, but the message isn't reveailing it. I am fairly certain that I have done this in the past with no ill effects. Show quoteHide quote "Brad" <B***@discussions.microsoft.com> wrote in message news:45751585-D68E-45B2-AB69-05B9BE41C0F0@microsoft.com... >I am storing an array which contains about a dozen chracter items to a > Session variable. Later, I need to use this array so I am doing the > following: > > Dim eventTypes As String() = DirectCast(Session("EventTypes"), String()) > If Date.Today <= closeDate Then > If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = > Session("JRFee") Else thisFee = Session("PEFee") > Else > If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = > Session("JRFee") Else thisFee = Session("DOSFee") > End If > > I have determined that the values are properly being stored into the > initial > array. I then assign a session variable to store this array. When I try > to > use the array in the segment above, I get the error "Object reference not > set > to an instance of an object - use the "new keyword". > > Obviously when I dim the eventTypes() something is wrong here. Please > help. > > Thanks for the information. Thank you both for the information, but for some reason it still does not
work. However, with a lot of things, I did a work-around and I am not using an array. I am just doing some string manipulation and comparing the string. I still would like to get the array to work, however. Thanks again. Show quoteHide quote "Roger Twomey" wrote: > If you have the array in the session I would do this: > > Dim EventTypes as String() > EventTypes = Session("EventTypes") > > If for some reason that doesn't work just put this line in the middle to try > (I know it's nuts but try it) > Redim EventTypes(0) > > Make sure that Date.Today, cblEntries.SelectedIndex and Session("PEFee") > etc. all exist. The problem might not be the array, but the message isn't > reveailing it. > > I am fairly certain that I have done this in the past with no ill effects. > > "Brad" <B***@discussions.microsoft.com> wrote in message > news:45751585-D68E-45B2-AB69-05B9BE41C0F0@microsoft.com... > >I am storing an array which contains about a dozen chracter items to a > > Session variable. Later, I need to use this array so I am doing the > > following: > > > > Dim eventTypes As String() = DirectCast(Session("EventTypes"), String()) > > If Date.Today <= closeDate Then > > If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = > > Session("JRFee") Else thisFee = Session("PEFee") > > Else > > If eventTypes(cblEntries.SelectedIndex) = "J" Then thisFee = > > Session("JRFee") Else thisFee = Session("DOSFee") > > End If > > > > I have determined that the values are properly being stored into the > > initial > > array. I then assign a session variable to store this array. When I try > > to > > use the array in the segment above, I get the error "Object reference not > > set > > to an instance of an object - use the "new keyword". > > > > Obviously when I dim the eventTypes() something is wrong here. Please > > help. > > > > Thanks for the information. > > >
Other interesting topics
vs2005 debugging on ws2k3 server
Net runtime crash Single Login Problem Losing data in a textbox on postback PreRender event question How to change the timeout value 2.0 height %'s not working When does Application_AuthenticateRequest fires? Access is denied: 'Interop.ADODB' error - almost ready to jump off the balcony! Tags inside value field of appsettings in web.config |
|||||||||||||||||||||||