Reputation: 29
I'm trying to store a list of table items in a Session variable to keep track of the last state (CHECKED or UNCHECKED) of the item's checkbox.
I start out by setting all values to UNCHECKED the first time the users loads the page. This part of the code seems to work:
model = Request.querystring("model")
If IsEmpty(Session(model)) Then
Set dicX = CreateObject("Scripting.Dictionary")
sqlStr = "SELECT DISTINCT level FROM IFPDB WHERE IFPDB.model='"
sqlStr = sqlStr & model
sqlStr = sqlStr & "'"
Set objRS = objConn.Execute(sqlStr)
' For each unique level get all of that levels menu names
Do While (Not objRS.EOF)
level = objRS("level")
dicX.Add level, CreateObject("Scripting.Dictionary")
' for each menu name set the initial state to OFF
sqlStr2 = "SELECT * FROM IFPDB WHERE IFPDB.model='"
sqlStr2 = sqlStr2 & model
sqlStr2 = sqlStr2 & "' AND IFPDB.level='"
sqlStr2 = sqlStr2 & level_name
sqlStr2 = sqlStr2 & "'"
Set objRS2 = objConn.Execute(sqlStr2)
Do While (Not objRS2.EOF)
menu_item = objRS2("menu_names")
dicX(level).Add menu_item, CreateObject("Scripting.Dictionary")
' add a dictionary item
dicX(level)(menu_item).Add "menu_state", "UNCHECKED"
objRS2.MoveNext
Loop
objRS.MoveNext
Loop
Set Session(model) = dicX
End If
The problem now comes when I try to read any of these values. No matter how I've tried to access them I get "Object_required:_'[undefined]'"
I've tried
' Check the last state of this option
menu_name = objResult("menu_names")
response.write(menu_name & "<br>") ' writes correctly
If Not IsEmpty(Session(model))
my_state = Session(model)(current_level)(menu_name).Item("menu_state") ' dies here
response.write(my_state & "<br>")
End If
' tried these as well
my_state = Session(model)(current_level)(menu_name)("menu_state")
'and
my_state = Session(model)(current_level).Item(menu_name).Item("menu_state")
'and others
I guess I just don't know how to read that Session variable that I made. Any ideas?
Upvotes: 1
Views: 1946
Reputation: 1233
See: Can I store a Scripting Dictionary in a session variable?
You have to extract the dictionary from the session and put in into a fresh variable.
dim state
set state = Session(model)
You are also missing the 'item' part:
my_state = state.item(current_level).item(menu_name).item("menu_state")
Upvotes: 1