Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2008, 01:19 PM
Authorized User
 
Join Date: Jan 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default progbar + sql connection

Hi - I am new to this site and ASP. I am learning 3.0 (my company has alot of stuff coded in the classic ASP).

I have seen this progbar code being used to show a progress bar on your site while you are waiting for an operation to complete the following code is what I am using:

<%Response.Buffer = True
server.scriptTimeout =25000
%>
<div id="ProgBar" style="font-family:Verdana; font-size=9pt;">Progress:<BR>
<TABLE style="color:red;" HEIGHT="16" Border=1>
<TR><TD BGCOLOR=RED ID="statuspic"></TD></TR></TABLE>
</div>
<script language="Javascript">var progBarWidth=250;
</script>
<%
iProcessedSoFar = 0
iTotalRecords = 300
ii = 0
strHTML="<Table width='80%'><TR><TD Width='100%' BGCOLOR='gray' align='CENTER'>Results:<TD><TR>"
for i = 0 to iTotalRecords

strHTML = strHTML & "<TR width='100%'><td width='100%' BGCOLOR='#FFCC66'>Your results</td></tr>"
    'added delay loop
    for ii = 0 to 40000
    ii = ii +1
    next
iProcessedSoFar = iProcessedSoFar + 1
pctComplete = (iProcessedSoFar / iTotalRecords)
    If i mod 8 = 0 then
        ShowProgress pctComplete
        response.write pctComplete & "<BR>"
    End if
Next
FinishProgress

strHTML=strHTML &"</TABLE>"
Response.write strHTML

Sub ShowProgress(nPctComplete)
response.write "here"
Response.Write "<SCR" & "IPT LANGUAGE='JavaScript'>" & vbCrlf
Response.Write "statuspic.width = Math.ceil(" & nPctComplete & " * 250);" &vbCrlf
Response.Write "</SCR" &"IPT>"
response.flush
End Sub

Sub FinishProgress
'Response.Write "<SCR" &"IPT LANGUAGE='JavaScript'>" & vbCrlf
'Response.Write "ProgBar.style.visibility ='hidden';" & vbCrLf
'Response.Write "</SCR" &"IPT>"
End sub
%>

I used this as my main page and I wanted to combine the following code:

<%
   Dim strConnect
   Response.Buffer = True
%>

<!-- METADATA TYPE="typelib"
              FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<HTML>
<HEAD>
<TITLE>ph0neman's music database</TITLE>
</HEAD>
<BODY>
<%
  Dim intChosenRecord, strDirection, strOutputString, intCounter, intNoOfRecords
  If Request.Form("ChosenRec") <> "" Then
    intChosenRecord = Request.Form("ChosenRec")
    strDirection = Request.Form("Dir")
  Else
    intChosenRecord = 1
    strDirection = "Forward"
  End If

  Dim objRS
  Set objRS = Server.CreateObject("ADODB.Recordset")
  objRS.Open "top2000", strConnect, adOpenStatic, adLockReadOnly, adCmdTable
  intNoOfRecords = objRS.RecordCount
  objRS.Move intChosenRecord-1
  strOutputString = "<TABLE BORDER=1>" & _
            "<TR><TD WIDTH=""5%""><B>ID</B></TD>" & _
            "<TD><B>Artist</B></TD>" & _
            "<TD><B>Album</B></TD>" & _
            "<TD><B>Track</B></TD>" & _
            "<TD><B>Song Title</B></TD>" & _
            "<TD><B>Year<B></TD></TR>"
  If strDirection = "Forward" Then
    While Not objRS.EOF
      strOutputString = strOutputString & "<TR>" & _
    "<TD>&nbsp;" & objRS("ID") & "</TD>" & _
    "<TD>" & objRS("Artist") & "</TD>" & _
    "<TD>" & objRS("Album") & "</TD>" & _
    "<TD>" & objRS("Track") & "</TD>" & _
    "<TD>" & objRS("Title") & "</TD>" & _
    "<TD>" & objRS("Year") & "</TD>" & _
        "</TR>"
      objRS.MoveNext
    Wend
    objRS.MoveFirst
    For intCounter = 1 To intChosenRecord-1
      strOutputString = strOutputString & "<TR>" & _
    "<TD>&nbsp;" & objRS("ID") & "</TD>" & _
    "<TD>" & objRS("Artist") & "</TD>" & _
    "<TD>" & objRS("Album") & "</TD>" & _
    "<TD>" & objRS("Track") & "</TD>" & _
    "<TD>" & objRS("Title") & "</TD>" & _
    "<TD>" & objRS("Year") & "</TD>" & _
        "</TR>"
      objRS.MoveNext
    Next
  Else
    While Not objRS.BOF
      strOutputString = strOutputString & "<TR>" & _
    "<TD>&nbsp;" & objRS("ID") & "</TD>" & _
    "<TD>" & objRS("Artist") & "</TD>" & _
    "<TD>" & objRS("Album") & "</TD>" & _
    "<TD>" & objRS("Track") & "</TD>" & _
    "<TD>" & objRS("Title") & "</TD>" & _
    "<TD>" & objRS("Year") & "</TD>" & _
        "</TR>"
      objRS.MovePrevious
    Wend
    objRS.MoveLast
    For intCounter = intNoOfRecords To intChosenRecord+1 Step -1
      strOutputString = strOutputString & "<TR>" & _
    "<TD>&nbsp;" & objRS("ID") & "</TD>" & _
    "<TD>" & objRS("Artist") & "</TD>" & _
    "<TD>" & objRS("Album") & "</TD>" & _
    "<TD>" & objRS("Track") & "</TD>" & _
    "<TD>" & objRS("Title") & "</TD>" & _
    "<TD>" & objRS("Year") & "</TD>" & _
        "</TR>"
      objRS.MovePrevious
    Next
  End If
  strOutputString = strOutputString & "</TABLE>"
  objRS.Close
  Set objRS = Nothing
  Response.Write strOutputString
  Response.Flush
%>
<BR>
<FORM ACTION="Moving.asp" METHOD="POST">
  <H2>Format the list!</H2>
  Where do you want this list to begin? Record
  <SELECT SIZE=1 NAME="ChosenRec">
  <%
    For intCounter=1 To intNoOfRecords
      Response.Write "<OPTION VALUE=" & intCounter & ">" & intCounter & "</OPTION>"
    Next
  %>
  </SELECT><BR><BR>
  Do you want the records to be listed
  in <INPUT TYPE="RADIO" NAME="Dir" VALUE="Forward" CHECKED><B> forward</B></INPUT>
  or <INPUT TYPE="RADIO" NAME="Dir" VALUE="Reverse"> <B>reverse</B></INPUT>
  order (select one)?
  <INPUT TYPE="SUBMIT" VALUE="View the list"></INPUT>
</FORM>

<A HREF="DisplaySource.asp?FileName=
<%= Server.URLEncode(Request.ServerVariables("PATH_INF O")) %> ">
Click here to see ASP source</A>

</BODY>
</HTML>


Forgive my ignorance. I am not really needing this to work only to try to understand the logic behind it. I originally tried to put my code (the 2nd one listed here), into the progbar code and I can get my results from my SQL query but I cant get the progress bar to show progress while I am waiting for the query.

Can anyone provide some insight into what I am doing wrong?

Here is what I am trying to run:
<%
Response.Buffer = True
server.scriptTimeout =25000

%>
<div id="ProgBar" style="font-family:Verdana; font-size=9pt;">Progress:
<TABLE style="color:red;" HEIGHT="16" Border=1><TR><TD BGCOLOR=RED ID=statuspic></TD></TR></TABLE><BR>
</div>
<script language="Javascript">var progBarWidth=250;</script>

<%
iProcessedSoFar = 0
iTotalSize = 2000 'Actual file size
ii = 0
for i = 0 to iTotalSize
'theDate = Date() + iProcessedSoFar
' next few lines are just a surrogate for whatever your processing function to be timed
    'for ii = 0 to 2000
    'ii = ii +1
    'next
iProcessedSoFar = iProcessedSoFar + 1
pctComplete = (iProcessedSoFar / iTotalSize)
if i mod 8 = 0 then
ShowProgress pctComplete
'response.write pctComplete & "<BR>"
end if
next
FinishProgress

Sub ShowProgress(nPctComplete)
Response.Write "<SCR" & "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write "statuspic.width = Math.ceil(" & nPctComplete & " * 250);" & vbCrlf
Response.Write "</SCR" & "IPT>"
response.flush
End Sub
Sub FinishProgress
Response.Write "<SCR" & "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write "ProgBar.style.visibility ='hidden';" & vbCrLf
Response.Write "</SCR" & "IPT>"
end sub
%>


I have tried inserting the code into the the progbar script instead of using an include statement but still no luck.

Thanks


keep your kneeze in the breeze
__________________
keep your kneeze in the breeze
 
Old January 16th, 2008, 06:17 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

I havnt wadded through all your code however have a comment. You say:

;;;but I cant get the progress bar to show progress while I am waiting for the query.
querys should take nano seconds (if not a couple of seconds max) why would you want to show a progress bar? IME if querys take long enough to have a need for any kind of progress bar the page and its construction needs to be looked at.

Wind is your friend
Matt
www.elitemarquees.com.au
 
Old January 17th, 2008, 09:50 AM
Authorized User
 
Join Date: Jan 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi mat41 -

Thanks for your response. Basically, what I am doing is that I have Ampache running on a mysql server. I have over 50,000 songs in that db and just for the sake of learning ASP and how things worked... I exported that from mysql and imported it into MS SQL Server 2005. I made a connection through ASP to this database. For testing purposes I ran queries on the top 100, top 1000, top 2000, etc... once I got over 5000 the query starts to take some time. I wanted the progress bar to notify the user that the query is running and there will be a result soon.

Truthfully mat41, I agree with your comment about how it shouldnt take a significant amount of time to run queries.. as I mentioned, I am really only trying to figure out how to fix it so I can understand how it works.

Thanks again for your response however, I appreciate any feedback I get.

sincerely

ph0neman





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Connection - Chapter 9 mdfinch BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 October 23rd, 2007 12:46 AM
sql connection msrnivas .NET Web Services 1 January 26th, 2004 12:25 PM
Global SQL connection MichaelTJ .NET Web Services 16 December 16th, 2003 09:34 PM
SQL Server Connection mpeterson Classic ASP Databases 1 July 8th, 2003 09:50 PM
Connection with sql server arshad mahmood VB Databases Basics 1 June 19th, 2003 10:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.