View Single Post
Old 01-30-2013, 09:37 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I can't help it. I'm a pedant.

Here's how I might have coded that:
Code:
Function view_NSMC_News(arg1)
    dim mn,mn_imgsrc,mn_title,mn_content,objConn,objRs,sql,SlideNavSquares,snsclass

    ' err.clear ' totally unneeded...On Error automatically does Clear as well

    On Error Resume Next
        set objConn=server.CreateObject("ADODB.Connection")
        objConn.ConnectionTimeout=5
        objConn.Open testdsn
	
	sql = "SELECT TOP "&arg1&" * FROM dbo.[12_NEWS] ORDER BY NEWID()"
	Set objRs = objConn.Execute( sql )
        if Err.Number <> 0 then
%>
	    <div class="article img_left">
                <img src="/images/nsmcconnect/blank.png" width="150" height="150" alt="No Image" />
                <h2>Error Occured</h2>
                <p><%=err.description%></p>
           </div>
<%
           Exit Function
       End If
    On Error GoTo 0 ' we *want* to see errors past here
   
    if objRs.EOF then 
%>
        <div class="article img_left">
            <img src="/images/nsmcconnect/blank.png" width="150" height="150" alt="No Image" />
            <h2>No Articles Found</h2>
            <p>No current articles are posted at this time.</p>
        </div>
<%
        Exit Function
    End If
    ' okay...if we get here there really is a slideshow to show:
%>
    <div id="slideshow">
<%
    snsClass = " class=""active"" "
    SlideNavSquares = ""

    Do While Not objRs.EOF	
        mn_id = objRs("ID_News")		
        mn_imgsrc = "/images/news/mainnews/" & objRs("Image1")
	mn_title = objRs("Title")
	mn_content = objRs("Article")
        SlideNavSquares = SlideNavSquares _
                        & "<a href=""/"" " & snsclass & ">&nbsp;&nbsp;&nbsp;</a>"& vbCrLF
%>
        <a href="/" class="active" alt="<%=mn_title%>"><img src="<%=mn_imgsrc%>" />
            <div>
                <%=mn_content%>
                <span class="readmore">&lt;&nbsp;Read More</span>
            </div>
        </a>
<%
        snsclass = "" ' so only first <a> is active
        objRs.MoveNext
    Loop
    objRs.close ' not really needed...ending the function ends these variables' lives
    objConn.Close
%>
        <div id="slideroverlay">&nbsp;</div>
        <div id="slidenav">
            <%=SlideNavSquares%>
        </div><!--slidenav-->
    </div><!--slideshow-->
<%
End Function
%>
That would also execute a bit faster. Not much. A few milliseconds, perhaps.

Getting rid of Response.Write is the biggest performance boost.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 01-30-2013 at 09:40 PM..
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
DanInMa (01-31-2013)