Click to See Complete Forum and Search --> : Titlebar ticker with a difference?


smurfy
12-01-2002, 09:16 PM
Hi all.
Can't give a link to this as it's on a secure intranet but here is my code so far:
<HTML>
<HEAD>
<meta http-equiv="refresh" content="300">
</HEAD>
<BODY topmargin="10" leftmargin="10">
<%
dim i
dim cellString
dim callsthr
dim TodayDate
dim dbConn
dim sqlstr
dim results
dim snap_date_calc_day
dim snap_date_calc_month
dim snap_date_calc_year
dim snap_date_calc
If Day(Now()) < 10 then
snap_date_calc_day = "0" & Day(Now())
else
snap_date_calc_day = Day(Now())
End If
If Month(Now()) < 10 then
snap_date_calc_month = "0" & Month(Now())
else
snap_date_calc_month = Month(Now())
End If
snap_date_calc_year = Year(Now())
snap_date_calc = snap_date_calc_day & "/" & snap_date_calc_month & "/" &snap_date_calc_year
TodayDate = snap_date_calc
callsthr = 97.5
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open "Provider=SQLOLEDB.1;Server=@@@@@@;Database=@@@@@;User ID=######;Password=#####"
sqlstr = "Select snap_skill AS 'SKILL', max(snap_time) AS 'TIME', (((sum(cc_fact.calls_offered)-sum(cc_fact.abandoned))/sum(cc_fact.calls_offered))*100.0/1) AS 'OFFERED' FROM cc_fact WHERE snap_origin = ''" & TodayDate & "' GROUP BY snap_skill"
Set results = dbConn.Execute(sqlstr)
if results.eof then
response.write("Sorry, there is no Data present.")
else
%>
<table border=1>
<th colspan=14>Calls not abandoned after threshold by skillgroup as at <%=results("TIME")%> with threshold variable: <%=callsthr%>%</th>
<tr>
<%
dim percentage
dim score
dim target
i = 1
do until results.eof
score = CDbl(results("OFFERED"))
target = CDbl(callsthr)
If score < target Then
percentage = score
ELSE
percentage = target
End if
if percentage <> score then
cellString = "<td>" & results("SKILL") & "</td><td bgcolor='Lime'>" & results("OFFERED") & "</td>"
else
cellString = "<td>" & results("SKILL") & "</td><td bgcolor='Red'>" & results("OFFERED") & "</td>"
end if
if not i mod 7 = 0 then
response.write(cellString)
else
response.write(cellString)%></tr><%
end if
i = i + 1
results.movenext
loop
%>
</table>
<%
end if
%>
<SCRIPT LANGUAGE="JavaScript">
var titlechange;
var pagetitle = "CCDash ";
function scroll()
{
today = new Date();
sec = today.getSeconds();
var titlechange = "Count :" + sec;
pagetimer = setTimeout("scroll()", 5000);
document.title = pagetitle + titlechange;
}
if (document.all) scroll();
</script>
</BODY>
</HTML>

Now what this all does is queries a database every 5 minutes returning 7 sets of data (2 result items per set) to a table 14 columns wide.

Not only that, the "OFFERED" result cell is conditionally formatted (bgcolor) depending on the comparison of the result to the target figure.

That all works fine.

What I want to do now though is a little more tricky.
See my little document.title javascript at the bottom?
That was a test to make sure I can change the document title (this is all done within a Microsoft only environment so I don't care that Netscape etc won't allow doc title to be changed from body).

What I actually want to do is scroll through my result set from the query in the title bar!

As my query vbscript is server-side and changing titlebar is client side javascript I can't see how I can do it...
I've got a vague idea that I can perhaps NAME the table CELLS that the result sets are populating and use those names in some sort of loop to change the "titlechange" variable in the javascript.
Is that possible?

smurfy
12-02-2002, 06:47 PM
Thanks Dave, I agree that "Scroll" was a poor choice of words to describe the effect I want.
Perhaps "Cycle through the result set" would be more apt.

I like the thought of creating the Array with the Server query and then using Javascript to cycle through the array.

Working on it now, back soon :D

smurfy
12-02-2002, 10:47 PM
OK, there's probably a much tidier way to do this but here's what I've done (which does exactly what I wanted).
My VBScript to write the queryresults and create the comma seperated string to make a new array:

<%
dim percentage
dim score
dim target
dim result_array
i = 1
do until results.eof
score = CDbl(results("_OFFERED"))
target = CDbl(callsthr)
If score < target Then
percentage = score
ELSE
percentage = target
End if
if percentage <> score then
cellString = "<td>" & results("_SKILL") & "</td><td bgcolor='Lime'>" & results("_OFFERED") & "</td>"
if i = 1 then
result_array = results("_SKILL")&","&results("_OFFERED")
else
result_array = result_array + "," & results("_SKILL")&","&results("_OFFERED")
end if
else
cellString = "<td>" & results("_SKILL") & "</td><td bgcolor='Red'>" & results("_OFFERED") & "</td>"
if i = 1 then
result_array = results("_SKILL")&","&results("_OFFERED")
else
result_array = result_array + "," & results("_SKILL")&","&results("_OFFERED")
end if
end if
if not i mod 7 = 0 then
response.write(cellString)
else
response.write(cellString)%></tr><%
end if
i = i + 1
results.movenext
loop
%>
Now my javascript (using mangled version of a script taken from www.codebelly.com)

<SCRIPT LANGUAGE="JavaScript">
var rotationlist = "<%=result_array%>";
var rotation = new Array()
rotation = rotationlist.split(",");
var titlechange;
var reps = 1
// Copyright 2001 by www.CodeBelly.com
// Do *not* remove this notice.
// modified version by smurfy
// Set the overall speed (larger number = slower action).

var speed = 500

// DO NOT EDIT BETWEEN THESE LINES.
// ============================
var p=rotation.length;
var T="";
var C=0;
var mC=0;
var s=0;
var sT=null;
if(reps<1)reps=1;
function doTheThing(){
T=rotation[mC];
A();}
function A(){
s++
if(s>8){s=1}
//===============================
// you can fiddle with the patterns here...

if(s==1){document.title=T}

if(C<(8*reps)){
sT=setTimeout("A()",speed);
C++
}else{
C=0;
s=0;
mC++
if(mC>p-1)mC=0;
sT=null;
doTheThing();}}
doTheThing();
</script>

I now have the "_SKILL" name then the "_OFFERED" score cycling through on the title bar which is visible on the taskbar when window not visible to the user.

Thanks again Dave for pointing me in the right direction :D