469,945 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,945 developers. It's quick & easy.

Storing an array to a Session

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.
Dec 22 '05 #1
3 2091
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.

"Brad" <Br**@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.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.

Dec 22 '05 #2
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" <Br**@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.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.

Dec 22 '05 #3
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.

"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" <Br**@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.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.


Dec 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Francisco | last post: by
4 posts views Thread by mechweb | last post: by
reply views Thread by toton | last post: by
3 posts views Thread by Astha | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.