PDA

View Full Version : End if error still


GarretJax
03-13-2003, 01:03 AM
Having Probs with the logic in this baby...
Keep gettin end if error.......Right at the last line of code...



<!--#include file="Library.inc"-->
<HTML>
<HEAD>
<Body>
<% Response.Buffer = true %>


<%
dim strTitle, strAuthor, strIsbn, strCategory

strTitle = request.form("&txTitle&")
strAuthor = request.form("&txtAuthor&")
strIsbn = request.form("&txtIsbn&")
strCategory = request.form("&Category&")
%>
<%if strTitle = "" then%>
<%Response.write("Please enter a Title")%>
<table width="25%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22">
<param name="movie" value="btn_bytitle.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="btn_bytitle.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>
</object></td>
<%else%>

<%
dim objrsBooks, sql
sql = "SELECT * FROM Books WHERE Title = '" & strTitle & "'"
set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open sql, objConn
if objrsBooks.EOF or objrBooks.bof then%>
<P><H3>There is no book with that Title</H3></P>
<%Else%>

<TABLE BORDER="1" >
<TR>
<TH>Book ID</TH>
<TH>ISBN</TH>
<TH>Title</TH>
<TH>Author</TH>
<TH>Due Date</TH>
<TH>Member</TH>
</TR>

<%do while not objrsBooks.EOF
Response.Write "<TR align=center><TD>"
'Response.Write "<A HREF="" UpdateBook.asp?Action=return&BookID=" & objrsBooks("BookId") & """>"
Response.Write objrsBooks("BookId")
Response.Write "</a>"
Response.Write "</TD><TD>"
Response.Write objrsBooks("ISBN")
Response.Write "</TD><TD WIDTH=300>"
Response.Write objrsBooks("Title")
Response.Write "</TD><TD WIDTH=150>"
Response.Write objrsBooks("Author")
Response.Write "</TD><TD>"
'Response.Write FormatDateTime(objrsBooks("Date_Due"),2) 'ensure date is in short format
Response.Write "</TD><TD>"
Response.Write objrsBooks("User_Id")
Response.Write "</TD>"
objrsBooks.MoveNext
loop
objrsBooks.close%>


<%if strAuthor = "" then%>
<%Response.write("Please enter an Author")%>
<table width="25%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22">
<param name="movie" value="btn_byauthor.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="btn_byauthor.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>
</object></td>
<%else%>


<%
sql = "SELECT * FROM Books WHERE Author = '" & strAuthor & "'"
set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open sql, objConn
if objrsBooks.EOF or objrsBooks.bof then%>
<P><H3>There is no book by that Author</H3></P>

<%Else%>

<TABLE BORDER="1" >
<TR>
<TH>Book ID</TH>
<TH>ISBN</TH>
<TH>Title</TH>
<TH>Author</TH>
<TH>Due Date</TH>
<TH>Member</TH>
</TR>

<%do while not objrsBooks.EOF
Response.Write "<TR align=center><TD>"
'Response.Write "<A HREF="" UpdateBook.asp?Action=return&BookID=" & objrsBooks("BookId") & """>"
Response.Write objrsBooks("BookId")
Response.Write "</a>"
Response.Write "</TD><TD>"
Response.Write objrsBooks("ISBN")
Response.Write "</TD><TD WIDTH=300>"
Response.Write objrsBooks("Title")
Response.Write "</TD><TD WIDTH=150>"
Response.Write objrsBooks("Author")
Response.Write "</TD><TD>"
'Response.Write FormatDateTime(objrsBooks("Date_Due"),2) 'ensure date is in short format
Response.Write "</TD><TD>"
Response.Write objrsBooks("User_Id")
Response.Write "</TD>"
objrsBooks.MoveNext
loop
objrsBooks.close%>


<%if strIsbn = "" then%>
<%Response.write("Please enter an Isbn")%>
<table width="25%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22">
<param name="movie" value="btn_byisbn.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="btn_byisbn.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>
</object></td>
<%else%>






<%
sql = "SELECT * FROM Books WHERE Isbn = '" &strIsbn& "'" 'search for all outstanding books
set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open sql, objConn
If objrsBooks.EOF or objrsBooks.bof then%>
<P><H3>There is no book with that Isbn</H3></P>
<% Else%>

<TABLE BORDER="1" >
<TR>
<TH>Book ID</TH>
<TH>ISBN</TH>
<TH>Title</TH>
<TH>Author</TH>
<TH>Due Date</TH>
<TH>Member</TH>
</TR>

<% do while not objrsBooks.EOF
Response.Write "<TR align=center><TD>"
'Response.Write "<A HREF="" UpdateBook.asp?Action=return&BookID=" & objrsBooks("BookId") & """>"
Response.Write objrsBooks("BookId")
Response.Write "</a>"
Response.Write "</TD><TD>"
Response.Write objrsBooks("ISBN")
Response.Write "</TD><TD WIDTH=300>"
Response.Write objrsBooks("Title")
Response.Write "</TD><TD WIDTH=150>"
Response.Write objrsBooks("Author")
Response.Write "</TD><TD>"
'Response.Write FormatDateTime(objrsBooks("Date_Due"),2) 'ensure date is in short format
Response.Write "</TD><TD>"
Response.Write objrsBooks("User_Id")
Response.Write "</TD>"
objrsBooks.MoveNext
loop
objrsBooks.close%>


<%if strCategory = "" then%>
<%Response.write("Please enter a Category")%>
<table width="25%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22">
<param name="movie" value="btn_bycategory.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="btn_bycategory.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>
</object> </td>
<%else%>
<%
sql = "SELECT * FROM Books WHERE Category = '" &strCategory& "'" 'search for all outstanding books
set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open sql, objConn
If objrsBooks.EOF or objrsBooks.Bof then%>
<P><H3>There is no book in that Category</H3></P>
<%else%>

<TABLE BORDER="1" >
<TR>
<TH>Book ID</TH>
<TH>ISBN</TH>
<TH>Title</TH>
<TH>Author</TH>
<TH>Due Date</TH>
<TH>Member</TH>
</TR>

<%do while not objrsBooks.EOF
Response.Write "<TR align=center><TD>"
'Response.Write "<A HREF="" UpdateBook.asp?Action=return&BookID=" & objrsBooks("BookId") & """>"
Response.Write objrsBooks("BookId")
Response.Write "</a>"
Response.Write "</TD><TD>"
Response.Write objrsBooks("ISBN")
Response.Write "</TD><TD WIDTH=300>"
Response.Write objrsBooks("Title")
Response.Write "</TD><TD WIDTH=150>"
Response.Write objrsBooks("Author")
Response.Write "</TD><TD>"
'Response.Write FormatDateTime(objrsBooks("Date_Due"),2) 'ensure date is in short format
Response.Write "</TD><TD>"
Response.Write objrsBooks("User_Id")
Response.Write "</TD>"
objrsBooks.MoveNext
loop
objrsBooks.close
%>
<%end if%>
<%end If %><%end If %><%end If %><%end If %><%end If %><%end If %><%end If %><%end If %><%end If %>
<%end If %><%end If %><%end If %><%end If %><%end If %>

</TABLE>
</body>
</html>

david7777
03-13-2003, 07:44 AM
Before I go through this massive amnount of code, i just want to make sure that you are meanng to have so many nested if statements? about 15?

david7777
03-13-2003, 07:56 AM
Ok - first of all - i did a quick search on all if's in you code - there are only 8 if statements. You have 15 end if statements. It doesnt add up.

Unless you have left out some code, you need to cut down on your end if statements.

Morgoth
03-13-2003, 08:19 AM
That is not how you do it..

Honestly, when you make an if statement, before you start adding code, for now on, to prevent this problem, PLEASE! do this:


If Then

End If

OR

If Then

Else

End If


Then add your code. This will make sure you have all your if statements accounted for...

Try removing one by one and test the code to see if it runs or gives you another error.

Also next time when you paste code use the [ code ][ /code ] tags (no spaces). It will allow us to see indents and read the code better (that is, if you use indents at all. If not, do so, it will prevent this problem)

Indenting:


If String1 = String2 Then
Response.Write "My string equals the other string"
Else
For I = 0 to 4
Response.Write Integer(I)
Next
End If


Understand? It's just something to get into a habbit of..

You can also use indents for HTML!

<html>
<head>
<title>TITLE!</title>
</head>
<body>
<table>
<tr>
<td>
<h3>HELLO!</h3>
</td>
</tr>
<tr>
<td><h2>WORLD!</h2></td>
</tr>
</table>
</body>
</html>


I'm sorry.. you did indent but I had to look after I pushed the quote button.

So use the code tags next time.

Also, just to be nice, I will do through your code with a fine tooth comb, and solve your problem, and probibly make your code alot smaller.

I started this, and I found a few HTML errors too.

It really seems you don't know alot about ASP And it looks to me like you are connecting all the If statements togther when they really don't need to be..

You have alot of code that is repeated...
I will see what I can do for you there.

Morgoth
03-13-2003, 09:04 AM
I now see why you used all those If statments like that.

I suggest you don't do it that way.
I suggest you allow a person to go through to find out that they missed what categories without having to submit more then once!
So let's change that, and lets add some code together that's the same. Or change one thing so it displays what you need.

So far the code I remade is almost 100 lines shorter.

I also didn't like what you did with the </table> tag at the bottom. You left out </tr> for the last little bit for all of your flash embeds...
So that was a problem just waiting to happen.

Morgoth
03-13-2003, 09:38 AM
So this is what I came up with.. took me a few, but I believe it works with your database, you'll need to test that for me.
If there is a problem with it, just tell me what the error is, and I'll fix it.

If I had time, and the database, I might be able to make the code even smaller.




<!--#include file="Library.inc"-->

<%
Sub Flashbtn(ByVal String1)
%>

<table width="25%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22">
<param name="movie" value="btn_by<%=String1%>.swf">
<param name="quality" value="high">
<param name="base" value=".">
<embed src="btn_by<%=String1%>.swf" base="." quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>
</object>
</td>
</tr>
</table>

<%
End Sub
Sub BookList
%>

<table border="1">
<tr>
<td>Book ID</td>
<td>ISBN</td>
<td>Title</td>
<td>Author</td>
<td>Due Date</td>
<td>Member</td>
</tr>

<%
End Sub
Sub BookListings
%>

<tr align="center">
<td><!-- <a href="UpdateBook.asp?Action=return&BookID=<%=objrsBooks("BookId")%>"><%=objrsBooks("BookId")%> --></a></td>
<td><%=objrsBooks("ISBN")%></td>
<td width="300"><%=objrsBooks("Title")%></td>
<td width="150"><%=objrsBooks("Author")%></td>
<td><!-- <%=FormatDateTime(objrsBooks("Date_Due"),2)%> --></td>
<td><%=objrsBooks("User_Id")%></td>
</tr>

<%
End Sub
Sub EndBookList
%>

</table>

<%
End Sub
%>


<html>
<head>
<title>Untitled Document Thingy</title>
</head>
<body>


<%
Response.Buffer = True

Dim StrTitle, StrAuthor, StrIsbn, StrCategory, objrsBooks, SQL, objConn

StrTitle = Request.Form("&txTitle&")
StrAuthor = Request.Form("&txtAuthor&")
StrIsbn = Request.Form("&txtIsbn&")
StrCategory = Request.Form("&Category&")

If StrTitle = "" Then
Response.Write("Please enter a Title")
Call Flashbtn("title")
Else
SQL = "SELECT * FROM Books WHERE Title = '" & StrTitle & "'"
Set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open SQL, objConn
If objrsBooks.EOF OR objrBooks.BOF Then
Response.Write("<P><H3>There is no book with that Title</H3></P>")
Else
Call BookList
Do While NOT objrsBooks.EOF
Call BookListings
objrsBooks.MoveNext
Loop
Call EndBookList
objrsBooks.Close
End If
End If

If StrAuthor = "" Then
Response.Write("Please enter an Author")
Call Flashbtn("author")
Else
SQL = "SELECT * FROM Books WHERE Author = '" & StrAuthor & "'"
Set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open SQL, objConn
If objrsBooks.EOF OR objrsBooks.BOF Then
Response.Write("<P><H3>There is no book by that Author</H3></P>")
Else
Call EndBookList
Do while not objrsBooks.EOF
Call BookListings
objrsBooks.MoveNext
Loop
Call EndBookList
objrsBooks.Close
End If
End If

If StrIsbn = "" Then
Response.write("Please enter an Isbn")
Call Flashbtn("isbn")
Else
SQL = "SELECT * FROM Books WHERE Isbn = '" &StrIsbn& "'" 'search for all outstanding books
Set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open SQL, objConn
If objrsBooks.EOF OR objrsBooks.BOF Then
Response.Write("<P><H3>There is no book with that Isbn</H3></P>")
Else
Call BookList
Do While Not objrsBooks.EOF
Call BookListings
objrsBooks.MoveNext
Loop
Call EndBookList
objrsBooks.Close
End If
End If

If StrCategory = "" Then
Response.write("Please enter a Category")
Call Flashbtn("category")
Else
SQL = "SELECT * FROM Books WHERE Category = '" &StrCategory& "'" 'search for all outstanding books
Set objrsBooks = Server.CreateObject("ADODB.Recordset")
objrsBooks.Open SQL, objConn
If objrsBooks.EOF OR objrsBooks.BOF Then
Response.Write("<P><H3>There is no book in that Category</H3></P>")
Else
Call BookList
Do While Not objrsBooks.EOF
Call BookListings
objrsBooks.MoveNext
Loop
Call EndBookList
objrsBooks.Close
End If
End If
%>


</body>
</html>



This code is approximatly 4.20KB
Your code is approximatly 7.79KB

GarretJax
03-13-2003, 04:54 PM
Thanks very much hell of alot simpler the way you have done it.......
Found solution that works on my own amazingly.... I will give yours a shot as well looks much more efficient......

Thanks again.....will have many more questions to come in the future.........

Morgoth
03-13-2003, 08:05 PM
Well, I just hope you understand it, and that it works!
I only see one problem that I didn't test, and that might be it.

Remember! There is no reason you have many if statments connected together like that, and if I had the database, I would probibly be able to turn the entire thing into 2 if statements inclosed in a For loop.