Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While Wend syntax

Status
Not open for further replies.

madanthrax

IS-IT--Management
Sep 15, 2001
123
AT
Hi,

I have a view created from two tables, one with uploaded file data (url, link text, date etc) and one with the folders info. The view gives me the folder name attached to every row of file data.

I need to place records in about 9 places on an asp page. They need to have the folder title first then a list of the contained uploaded files underneath. I could make 18 recordsets filtering using 'where' statement and plop them on the page easily.

However above is messy so I want to try and use a single recordset:
Code:
<%
Dim rsInsagFiles
Dim rsInsagFiles_cmd
Dim rsInsagFiles_numRows

Set rsInsagFiles_cmd = Server.CreateObject ("ADODB.Command")
rsInsagFiles_cmd.ActiveConnection = MM_NSweb_STRING
rsInsagFiles_cmd.CommandText = "SELECT * FROM dbo.vw_InsagPublic" 
rsInsagFiles_cmd.Prepared = true

Set rsInsagFiles = rsInsagFiles_cmd.Execute
rsInsagFiles_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsInsagFiles_numRows = rsInsagFiles_numRows + Repeat1__numRows
%>

And the plan is to use Wend statements similar to this below for the titles with something like an if then statement in it:
Code:
<% 
While ((Repeat1__numRows <> 0) AND (NOT rsInsagFiles.EOF)) 
%>
 <h3><%=(rsInsagFiles("FolderName"))%></h3>
<% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsInsagFiles.MoveNext()
Wend 
%>

I have tried using <% if rsInsagFiles("ID") = 199 then %> (199 is the folder ID) but this gives me multiple instances of the folder title (from each file record).

When I attempt to stop the loop when the first 199 record is found I always get an error. I have tried using UNTIL but I am not sure what I am doing..... The code below does not work but maybe someone can see what I am trying to do:
Code:
<% 
While ((Repeat1__numRows <> 0) AND (NOT rsInsagFiles.EOF)) 
%>
<% if rsInsagFiles("ID") = 199 then %>
 <h3><%=(rsInsagFiles("FolderName"))%></h3>
<%
else
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsInsagFiles.MoveNext()
Wend
end if 
%>
Any help would be greatly appreciated.

Anthony

[sub]&quot;Nothing is impossible until proven otherwise&quot;[/sub]​
 
[tt]<%
While ((Repeat1__numRows <> 0) AND (NOT rsInsagFiles.EOF))
%>
<% if rsInsagFiles("ID") = 199 then %>
<h3><%=(rsInsagFiles("FolderName")[blue].value[/blue])%></h3>
<%
[red]'[/red]else
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
[red]end if[/red]
rsInsagFiles.MoveNext()
Wend
[red]'[/red]end if
%>
[/tt]
Why the condition on Repeat1__numRows<>0 is beyond me if it starts with a value -1.
 
How about this?

Code:
<%
    [!]Do[/!] While ((Repeat1__numRows <> 0) And (Not rsInsagFiles.EOF))
        If rsInsagFiles("ID") = 199 Then
            %><h3><%=(rsInsagFiles("FolderName"))%></h3><%
            [!]Exit Do[/!]
        Else
            Repeat1__index = Repeat1__index + 1
            Repeat1__numRows = Repeat1__numRows - 1
            rsInsagFiles.MoveNext()
        End If
    [!]Loop[/!]

%>

If you use a Do While/Loop structure, you can exit the loop early using the Exit Do statement.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Wow fast replies!

Great job George! Now I know. It works perfectly. Thanks.

Tsuji thanks for the help too but maybe my explanation was a bit lacking.

Anthony.

[sub]&quot;Nothing is impossible until proven otherwise&quot;[/sub]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top