K
Ken Fine
I have a menu system that has nodes that can be opened or closed. In an
effort to make my code more manageable, I programmed a little widget tonight
that keeps track of the open/active item and automatically builds
querystrings for my redirect URLS. The code for this follows. It defines an
ASP Dictionary object, and key/value pairs for each, and builds appropriate
querystrings based on comparison with a status variable.
The way it works for now is I manually declare and re-declare a variable
("CurrentContentClass") in places throughout the code where there is a new
menu item. I embed this same block of code repeatedly through my
application, one for each menu node. This is a really stupid approach, and
I'm sure there's a better way.
Better would be to create a single function into which you could feed
parameters and get output. I've used lots of functions in my auspicious
career in ASP, but I've never created one myself.
Can anyone suggest tutorials or approaches such that I can learn how to
create my own functions? Any guidance based on what's below?
Note that there's some (lots) of redundancy and cluelessness expressed the
code below. Some of this is newbieness; some is to accomodate future
functionality. While I'd appreciate any ideas for optimization, what I'm
really looking for here is a general "how-to" on making functions.
Thanks for any help.
-KF
<%Dim dicRedirect
Set dicRedirect=Server.CreateObject("Scripting.Dictionary")
dicRedirect.Add "Experts","uwelns"
dicRedirect.Add "UPhoto","uspns"
dicRedirect.Add "Uweek","uwkns"
dicRedirect.Add "Releases","uwnrns"
' The value element of the key/value pairs above is used to build the URL
%>
<%
Dim RedirectStringOpen
Dim counter
Dim SecondCounter
counter=0
SecondCounter=0
'set variables "counter" and "SecondCounter" to zero
Dim currentDictionaryCategory
'something to store the active value in the dictionary as we loop through
For each whatever in dicRedirect
' for every item in the dictionary I just defined
currentDictionaryCategory= Cstr(dicRedirect.item(whatever))
'set the currentDictionaryCategory to the value setting of the active
key/value pair
counter=counter+1
'Increment the counter by one. Counter is unused for now, may find
application later
if counter<>1 then
if Cstr(currentDictionaryCategory) = Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen & "&" &
dicRedirect.item(whatever)&"=o")
' If the current dictionary item is the same as the variable
CurrentContentClass, then add the dictionary item name to the QueryString
with a value of "o", e.g. uwkns=o
if Cstr(currentDictionaryCategory) <> Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen & "&" &
dicRedirect.item(whatever)&"=c")
' If the current dictionary item is not the same as the variable
CurrentContentClass, then add the dictionary item name to the QueryString
with a value of "c", e.g. uwkns=c
end if
if counter=1 then
if Cstr(currentDictionaryCategory) = Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen &
dicRedirect.item(whatever)&"=o")
if Cstr(currentDictionaryCategory) <> Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen &
dicRedirect.item(whatever)&"=c")
end if
If SecondCounter<>1 Then
redirectStringClosed = (redirectStringClosed & "&" &
dicRedirect.item(whatever)&"=c")
else
redirectStringClosed = (redirectStringClosed &
dicRedirect.item(whatever)&"=c")
end if
Next
%>
effort to make my code more manageable, I programmed a little widget tonight
that keeps track of the open/active item and automatically builds
querystrings for my redirect URLS. The code for this follows. It defines an
ASP Dictionary object, and key/value pairs for each, and builds appropriate
querystrings based on comparison with a status variable.
The way it works for now is I manually declare and re-declare a variable
("CurrentContentClass") in places throughout the code where there is a new
menu item. I embed this same block of code repeatedly through my
application, one for each menu node. This is a really stupid approach, and
I'm sure there's a better way.
Better would be to create a single function into which you could feed
parameters and get output. I've used lots of functions in my auspicious
career in ASP, but I've never created one myself.
Can anyone suggest tutorials or approaches such that I can learn how to
create my own functions? Any guidance based on what's below?
Note that there's some (lots) of redundancy and cluelessness expressed the
code below. Some of this is newbieness; some is to accomodate future
functionality. While I'd appreciate any ideas for optimization, what I'm
really looking for here is a general "how-to" on making functions.
Thanks for any help.
-KF
<%Dim dicRedirect
Set dicRedirect=Server.CreateObject("Scripting.Dictionary")
dicRedirect.Add "Experts","uwelns"
dicRedirect.Add "UPhoto","uspns"
dicRedirect.Add "Uweek","uwkns"
dicRedirect.Add "Releases","uwnrns"
' The value element of the key/value pairs above is used to build the URL
%>
<%
Dim RedirectStringOpen
Dim counter
Dim SecondCounter
counter=0
SecondCounter=0
'set variables "counter" and "SecondCounter" to zero
Dim currentDictionaryCategory
'something to store the active value in the dictionary as we loop through
For each whatever in dicRedirect
' for every item in the dictionary I just defined
currentDictionaryCategory= Cstr(dicRedirect.item(whatever))
'set the currentDictionaryCategory to the value setting of the active
key/value pair
counter=counter+1
'Increment the counter by one. Counter is unused for now, may find
application later
if counter<>1 then
if Cstr(currentDictionaryCategory) = Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen & "&" &
dicRedirect.item(whatever)&"=o")
' If the current dictionary item is the same as the variable
CurrentContentClass, then add the dictionary item name to the QueryString
with a value of "o", e.g. uwkns=o
if Cstr(currentDictionaryCategory) <> Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen & "&" &
dicRedirect.item(whatever)&"=c")
' If the current dictionary item is not the same as the variable
CurrentContentClass, then add the dictionary item name to the QueryString
with a value of "c", e.g. uwkns=c
end if
if counter=1 then
if Cstr(currentDictionaryCategory) = Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen &
dicRedirect.item(whatever)&"=o")
if Cstr(currentDictionaryCategory) <> Cstr(CurrentContentClass)
then RedirectStringOpen = (RedirectStringOpen &
dicRedirect.item(whatever)&"=c")
end if
If SecondCounter<>1 Then
redirectStringClosed = (redirectStringClosed & "&" &
dicRedirect.item(whatever)&"=c")
else
redirectStringClosed = (redirectStringClosed &
dicRedirect.item(whatever)&"=c")
end if
Next
%>