Re: Looping!
- From: "Arpan" <arpan_de@xxxxxxxxxxx>
- Date: 25 Sep 2005 16:28:10 -0700
Sorry, McKirahan....you are right........the cause of the script
timeout error is because of the absence of objRS2.MoveNext. Also please
don't mind about excluding the comments. I did it just for brevity.
"strNAM=objRS1(iLoop)" is wrong; it should be "strNAM=objRS2(0)". Since
objRS2 will always have only 1 column at a time (only the DISTINCT
records of 1 column are being populated in each drop-down), using
"strNAM=objRS2(iLoop)" will generate an error; so the records under
that only column can be referenced using objRS2(0) (or
objRS2(0).Value). This is the changed script which is working fine:
<%
Dim strSQL1,strSQL2
strSQL1 = "SELECT * FROM tblRecords"
Dim objRS1,objRS2
Set objRS1 = objConn.Execute(strSQL1)
Dim aSTR()
ReDim aSTR(0)
Dim iSTR
iSTR = 0
Dim sSTR
Sub Append(sSTR)
sSTR = sSTR & ""
If iSTR > UBound(aSTR) Then
ReDim Preserve aSTR(UBound(aSTR) + 1)
End If
aSTR(iSTR)=sSTR & vbCrLf
iSTR=iSTR + 1
End Sub
Function Concat()
ReDim Preserve aSTR(iSTR)
Concat=Join(aSTR,"")
Erase aSTR
ReDim aSTR(0)
iSTR=0
End Function
Dim iLoop,strCOL,strNAM
For iLoop = 0 To objRS1.Fields.Count-2
strSQL2="SELECT DISTINCT(" & objRS1(iLoop).Name & ") FROM
tblRecords WHERE " & objRS1(iLoop).Name & " IS NOT NULL ORDER BY " &
objRS1(iLoop).Name
Set objRS2=objConn.Execute(strSQL2)
strCOL=objRS1(iLoop).Name
Append "<select size='1' name='dd" & strCOL & "'
onChange='gotoURL(this.form.dd" & strCOL & ")' >"
Append "<option>Select</option>"
Do Until objRS2.EOF
strNAM=objRS2(0).Value
Append "<option value='Records.asp?colname=" & strCOL &
"&record=" & strNAM & "'>" & strNAM & "</option> "
objRS2.MoveNext
Loop
Append "</select>"
Next
Response.Write Concat()
%>
but it takes about 30 seconds to execute the script & that's too long a
time! Note that I am working on my local intranet IIS5 server (Win2K
Pro).
There's another doubt I have in my mind. When the code gets executed
for the first time, the "If" condition doesn't get executed because
iSTR=0 & aSTR being empty, UBound(aSTR)=0. Am I right? Then aSTR(0)
becomes equal to "<select size=1 name='ddCol1.......>" (for the 1st
column) & iSTR becomes equal to 1. So
aSTR(0)="<select size=1 name='ddCol1.......>"
but how is aSTR(0) being Preserved? On subsequent code execution, the
"If" condition gets satisfied; so the previous item in aSTR gets
Preserved but how is aSTR(0) getting Preserved? What is the flow of
execution of the code? Please clarify this point.
Actually I have never worked with Preserving & Erasing array items; so
these doubts are coming to my mind!
Thanks once again,
Regards,
Arpan
.
- Follow-Ups:
- Re: Looping!
- From: Arpan
- Re: Looping!
- References:
- Looping!
- From: Arpan
- Re: Looping!
- From: Arpan
- Re: Looping!
- From: McKirahan
- Re: Looping!
- From: Arpan
- Re: Looping!
- From: McKirahan
- Looping!
- Prev by Date: Re: Looping!
- Next by Date: Re: Looping!
- Previous by thread: Re: Looping!
- Next by thread: Re: Looping!
- Index(es):
Relevant Pages
|