The following are some tricks and tools I created to speed up asp classic.
Menu:
Getting options from the menu will dramatically slow down the web page. This is because each time the page redraws, the server has to access the database to access the database and retrieve the information. One way is to have a console program (at the time, I did it in Java to pull the data and save it to a text file). Once, you have it in the text file you can then retrieve it using "File System Object".
To make it easier to maintain, I add an entry in the global.asa to point to the file. As in:
Application("procList") = "c:\extfile\proc.txt"
Your asp script can then check to see if the setting is available:
procFile = Application("procList")
if (procFile = "") then
response.write "Error Critical setup missing - step List"
response.end
end if
After that you can read that into an array, as shown below:
set fso = Server.CreateObject("Scripting.FileSystemObject")
redim p4Lookup(sizeInc)
p4Size = sizeInc
p4Max = 0
if (fso.FileExists(procFile)) then
set file = fso.OpenTextFile(procFile,1)
while file.AtEndOfStream <> True
tline = trim(file.readline())
if (tline <> "") then
p4Max = p4Max + 1
if (p4Max > p4Size) then
p4Size = p4Size + sizeInc
redim preserve p4Lookup(p4Size)
end if
p4Lookup(p4Max) = tline
end if
wend
file.close
set fso = nothing
else
response.write "Error - critical file missing - prodList4"
response.end
end if
You can then create a function to draw the menu. You can then have create a subroutine and then place it between your html tags as follows:
<% ListArray p4Lookup, p4Max, "prod4", selprod4 %>
ListArray is the name of the subroutine, p4Lookup is the list read as shown above and p4Max is the number of items in the list. prod4 is the name of the menu item and selprod4 is the selected items.
To obtain the information, you will just do the following:
<%
selprod4 = Request.form("prod4")
%>
The list array subroutine is as follows:
You can also have a script to allow multiple selection listbox as follows:
'==================================================================
' Create a form (pulldown) list from an Array
'==================================================================
Sub ListArray(aList, aSize, SelName, SelRec)
'Parameters are as follows:
' aList - array of options
' aSize - number of items in array
' SelName - name of form selection input
' SelRec - Record selected
DIM i
Response.Write "<select name=" & SelName & ">"
For i = 1 to aSize
Response.Write "<option "
if (aList(i) = SelRec) then
Response.Write "selected "
end if
Response.write "value=""" & _
aList(i) & """>"
Response.Write aList(i) & "</option>"
Next
Response.Write "</select>"
End Sub
'=====================================================
' Create Multiple Select list based on an array
' Parameters:
' aList Array List to use
' aLim Size of the array list
' selName Name for the multi select list
' selectedList Array containing the list of values selected
' selListSize Size of the selectedList
' Osize Size of the multiselect list
'=====================================================
sub mSelList(aList, aLim, selName, selectedlist, selListSize, Osize)
DIM i
response.write "<select name=" & selName & " size=" & Osize & " multiple>"
for i = 1 to aLim
response.write "<option"
if inList(selectedlist, selListSize, aList(i)) then
response.write " selected"
end if
response.write " value="""
response.write aList(i) & """>" & aList(i) & "</option>"
next
response.write "</select>"
end sub
No comments:
Post a Comment