Home All Groups Group Topic Archive Search About

Storing an array to a Session

Author
22 Dec 2005 3:31 PM
Brad
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.

Author
22 Dec 2005 3:38 PM
Marina
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.
Are all your drivers up to date? click for free checkup

Author
22 Dec 2005 4:38 PM
Roger Twomey
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.
Author
22 Dec 2005 7:29 PM
Brad
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.
>
>
>

Bookmark and Share