Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 March 21st, 2004, 08:40 PM
Authorized User
 
Join Date: Jan 2004
Location: Oklahoma City, , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I merge these two codes?

I have some ASP code and code for a scrolling thing I found. I'd like the scrolling thing to show the records (in the ASP Code) Here are the two codes...

ASP:
<%
Dim adoCon
Dim rsNews
Dim strSQL2
set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/stacygraff/database/mercy.mdb")
Set rsNews = Server.CreateObject("ADODB.Recordset")
strSQL2 = "SELECT tblNews.NewsInfo FROM tblNews;"
rsNews.Open strSQL2, adoCon
Response.Write ("<table border=""1"" cellpadding=""5"">")
Do While Not rsNews.EOF
    Response.Write ("<tr>")
    Response.Write ("<td>")
    Response.Write (rsNews("NewsInfo"))
    Response.Write ("</td>")
    Response.Write ("</tr>")
    Response.Write ("<br><br>")

    rsNews.MoveNext
Loop

Response.Write ("</table>")

rsNews.Close
Set rsNews = Nothing
Set adoCon = Nothing
%>


Javascript: (the code in red is where the records would go...)

<script language="JavaScript1.2">

/*
Fading Scroller- By DynamicDrive.com
For full source code, and usage terms, visit http://www.dynamicdrive.com
This notice MUST stay intact for use
*/

var delay=3000 //set delay between message change (in miliseconds)
var fcontent=new Array()
begintag='' //set opening tag, such as font declarations
fcontent[0]="<b>This is the Mercy School News!</b> There will be a form in the administrative management area that you can fill out and it should appear here.<br>"
fcontent[1]="This is the 2nd bit."
fcontent[2]="And, here is the 3rd bit of news."closetag=''

var fwidth='165px' //set scroller width
var fheight='270px' //set scroller height

var fadescheme=0 //set 0 to fade text color from (white to black), 1 for (black to white)
var fadelinks=1 //should links inside scroller content also fade like text? 0 for no, 1 for yes.

///No need to edit below this line/////////////////

var hex=(fadescheme==0)? 255 : 0
var startcolor=(fadescheme==0)? "rgb(255,255,255)" : "rgb(0,0,0)"
var endcolor=(fadescheme==0)? "rgb(0,0,0)" : "rgb(255,255,255)"

var ie4=document.all&&!document.getElementById
var ns4=document.layers
var DOM2=document.getElementById
var faderdelay=0
var index=0

if (DOM2)
faderdelay=2000

//function to change content
function changecontent(){
if (index>=fcontent.length)
index=0
if (DOM2){
document.getElementById("fscroller").style.color=s tartcolor
document.getElementById("fscroller").innerHTML=beg intag+fcontent[index]+closetag
linksobj=document.getElementById("fscroller").getE lementsByTagName("A")
if (fadelinks)
linkcolorchange(linksobj)
colorfade()
}
else if (ie4)
document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag
else if (ns4){
document.fscrollerns.document.fscrollerns_sub.docu ment.write(begintag+fcontent[index]+closetag)
document.fscrollerns.document.fscrollerns_sub.docu ment.close()
}

index++
setTimeout("changecontent()",delay+faderdelay)
}

// colorfade() partially by Marcio Galli for Netscape Communications. ////////////
// Modified by Dynamicdrive.com

frame=20;

function linkcolorchange(obj){
if (obj.length>0){
for (i=0;i<obj.length;i++)
obj[i].style.color="rgb("+hex+","+hex+","+hex+")"
}
}

function colorfade() {
// 20 frames fading process
if(frame>0) {
hex=(fadescheme==0)? hex-12 : hex+12 // increase or decrease color value depd on fadescheme
document.getElementById("fscroller").style.color=" rgb("+hex+","+hex+","+hex+")"; // Set color value.
if (fadelinks)
linkcolorchange(linksobj)
frame--;
setTimeout("colorfade()",20);
}

else{
document.getElementById("fscroller").style.color=e ndcolor;
frame=20;
hex=(fadescheme==0)? 255 : 0
}
}

if (ie4||DOM2)
document.write('<div id="fscroller" style="border:0px solid black;width:'+fwidth+';height:'+fheight+';padding: 2px"></div>')

window.onload=changecontent
</script>


<ilayer id="fscrollerns" width=&{fwidth}; height=&{fheight};><layer id="fscrollerns_sub" width=&{fwidth}; height=&{fheight}; left=0 top=0></layer></ilayer>



 
Old March 22nd, 2004, 04:35 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Stacy,

If I understand you correctly, you can put an ASP code block inside the JavaScript block to write out the records. The ASP will run at the server, and generate the JavaScript that is then send to the client. Something along these lines will work:
Code:
begintag='' //set opening tag, such as font declarations
<%
  ' Start ASP here
  ' Declare a counter as an array indexer
  Dim LoopCount
  LoopCount = 0
  ' Create and open your recordset here.
  ' I left that out for clarity
  Do While Not rsNews.EOF
    Response.Write ("fcontent[" & LoopCount & "]= '")
    Response.Write (rsNews("NewsInfo"))
    Response.Write ("';")
    rsNews.MoveNext
  Loop
  var fwidth='165px' //set scroller width
  This will write out something like this:

fcontent[0]= 'Bla 1';
fcontent[1]= 'Bla 2';
fcontent[2]= 'Bla 3';

Is this what you're after?

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old April 11th, 2004, 06:02 PM
Authorized User
 
Join Date: Jan 2004
Location: Oklahoma City, , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code I have now...

<%
Dim adoCon2
Dim rsNews
Dim strSQL2
set adoCon2 = Server.CreateObject("ADODB.Connection")
adoCon2.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../temp/database/mercy.mdb")
Dim LoopCount
LoopCount = 0
Set rsNews = Server.CreateObject("ADODB.Recordset")
strSQL2 = "SELECT tblNews.NewsInfo FROM tblNews;"
rsNews.Open strSQL2, adoCon2
    Response.Write ("<script language=JavaScript1.2>")
    Response.Write ("var delay=3000") //set delay between message change (in miliseconds)
    Response.Write ("var fcontent=new Array()")
    Response.Write ("begintag=''") //set opening tag, such as font declarations
Do While Not rsNews.EOF
    Response.Write ("fcontent[" & LoopCount & "]= '")
    Response.Write (rsNews("NewsInfo"))
    Response.Write ("';")
    rsNews.MoveNext
  Loop

    Response.Write ("</script>")

rsNews.Close
Set rsNews = Nothing
Set adoCon2 = Nothing
Set LoopCount = Nothing
%>
<script language="JavaScript1.2">
var fwidth='165px' //set scroller width
var fheight='270px' //set scroller height

var fadescheme=0 //set 0 to fade text color from (white to black), 1 for (black to white)
var fadelinks=1 //should links inside scroller content also fade like text? 0 for no, 1 for yes.

///No need to edit below this line/////////////////

var hex=(fadescheme==0)? 255 : 0
var startcolor=(fadescheme==0)? "rgb(255,255,255)" : "rgb(0,0,0)"
var endcolor=(fadescheme==0)? "rgb(0,0,0)" : "rgb(255,255,255)"

var ie4=document.all&&!document.getElementById
var ns4=document.layers
var DOM2=document.getElementById
var faderdelay=0
var index=0

if (DOM2)
faderdelay=2000

//function to change content
function changecontent(){
if (index>=fcontent.length)
index=0
if (DOM2){
document.getElementById("fscroller").style.color=s tartcolor
document.getElementById("fscroller").innerHTML=beg intag+fcontent[index]+closetag
linksobj=document.getElementById("fscroller").getE lementsByTagName("A")
if (fadelinks)
linkcolorchange(linksobj)
colorfade()
}
else if (ie4)
document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag
else if (ns4){
document.fscrollerns.document.fscrollerns_sub.docu ment.write(begintag+fcontent[index]+closetag)
document.fscrollerns.document.fscrollerns_sub.docu ment.close()
}

index++
setTimeout("changecontent()",delay+faderdelay)
}

// colorfade() partially by Marcio Galli for Netscape Communications. ////////////
// Modified by Dynamicdrive.com

frame=20;

function linkcolorchange(obj){
if (obj.length>0){
for (i=0;i<obj.length;i++)
obj[i].style.color="rgb("+hex+","+hex+","+hex+")"
}
}

function colorfade() {
// 20 frames fading process
if(frame>0) {
hex=(fadescheme==0)? hex-12 : hex+12 // increase or decrease color value depd on fadescheme
document.getElementById("fscroller").style.color=" rgb("+hex+","+hex+","+hex+")"; // Set color value.
if (fadelinks)
linkcolorchange(linksobj)
frame--;
setTimeout("colorfade()",20);
}

else{
document.getElementById("fscroller").style.color=e ndcolor;
frame=20;
hex=(fadescheme==0)? 255 : 0
}
}

if (ie4||DOM2)
document.write('<div id="fscroller" style="border:0px solid black;width:'+fwidth+';height:'+fheight+';padding: 2px"></div>')

window.onload=changecontent
</script>
<%
Response.Write("")
%>

<ilayer id="fscrollerns" width=&{fwidth}; height=&{fheight};><layer id="fscrollerns_sub" width=&{fwidth}; height=&{fheight}; left=0 top=0></layer></ilayer>

I now get two script errors and the screen is blank... Any ideas why?

 
Old April 12th, 2004, 03:51 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No, not really, because you're not telling us what kind of script errors, and the line number (if available) of the code that causes the error. This is quite a bit of code to digest and look for a possible error without knowing a little background information.

Other hints: upgrade your connection string. You're using a slow and old skool connection. Look here for more info: http://www.able-consulting.com/MDAC/...orMicrosoftJet

Also, look at the source of your page in the browser. Since you are generating JavaScript dynamically, you'll need to check that source and see if you generated it correctly.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: The Garden by P.J. Harvey (Track 8 from the album: Is This Desire?)





Similar Threads
Thread Thread Starter Forum Replies Last Post
What these Codes Mean? phungleon Access VBA 1 November 14th, 2006 08:50 AM
Need some more sample codes t.m.sundaram Visual Basic 2005 Basics 0 July 16th, 2006 08:16 AM
Please i need help with one of my codes skoob Java Espanol 1 April 11th, 2005 11:39 AM
Help:needs codes GoGoagg All Other Wrox Books 3 June 30th, 2004 01:24 AM
How do I merge these two codes? stacy Classic ASP Databases 1 March 22nd, 2004 04:30 AM





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