Link to home
Start Free TrialLog in
Avatar of edrz01
edrz01Flag for United States of America

asked on

Cross browser scroller - contents from external text file

I need to find or create a cross browser scroller where the contents scroll from right to left. The contents of the scroll message will need to come from an external file.

I am putting this into an ASP page.

Help?
Avatar of ddrudik
ddrudik
Flag of United States of America image

This will require an integration of both ASP and JS, first for ASP server-side to read the text file:
<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFS = oFSO.OpenTextFile(Server.MapPath("yourfile.txt"),1,false)
sText = oFS.readall
oFS.Close
set oFS = nothing
set oFSO = nothing
%>

You would put that code at the top of a new .asp file you create, with the following's solution HTML code below that:
https://www.experts-exchange.com/questions/21310994/Struggling-with-news-ticker.html

Finally, replace:
<span id="divText">
<nobr>crusin'... on a Sunday afternoon...to
<a id="link" href="https://www.experts-exchange.com/">Experts-Exchange</a>
</nobr></span>

With:
<span id="divText"><%=sText%></span>

And when you view the .asp page in a browser the text file will be read by ASP and displayed in the span to be scrolled by Javascript.
Avatar of edrz01

ASKER

ddrudik

Sorry it took me so long to get back - crazy week!

I attempted to make the changes you suggested but guess I missed something. I "assumed" you wanted me to merge your suggestions with the other EE tip. This is what I came up with - it didn't work.

Can you check it and see where I errored?

<html>
<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFS = oFSO.OpenTextFile(Server.MapPath("f:\test.txt"),1,false)
sText = oFS.readall
oFS.Close
set oFS = nothing
set oFSO = nothing
%>
<head>
<style type="text/css">
#scroller {
  overflow: hidden;
  border: 1px solid black;
  width: 250px;
  height: 1.25em;
}
</style>
<script type="text/javascript">
window.onload = init;

function init()
{
  obj = document.getElementById("message");

  // get width of message
  var clone = obj.cloneNode(true);
  document.body.appendChild(clone);
  totalWidth = clone.offsetWidth;
  document.body.removeChild(clone);

  // get width of scroller
  start = document.getElementById("scroller").offsetWidth;

  // start message on right-hand side of scroller
  horizPos = start;

  setInterval("scroll();", 25);
}

function scroll()
{
  horizPos = (horizPos == -1 * (totalWidth -1)) ? start: (horizPos - 1) % totalWidth;
  obj.style.marginLeft = horizPos + "px";

}
</script>
</head>

<body>
<div id="scroller">
<span id="divText"><%=sText%></span>
</div>
</body>
</html>
See the manual page on Server.MapPath:
http://msdn2.microsoft.com/en-us/library/ms524632.aspx
Server.MapPath is useful for referencing a file relative to the current script location, and if f:\ is a network drive you will likely not be too successful in your attempts to access with ASP due to permissions issues.

Copy test.txt to the same directory as the ASP script and then use:
<html>
<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFS = oFSO.OpenTextFile(Server.MapPath(".") & "\test.txt" ,1)
sText = oFS.readall
oFS.Close
set oFS = nothing
set oFSO = nothing
%>
<head>
<style type="text/css">
#scroller {
  overflow: hidden;
  border: 1px solid black;
  width: 250px;
  height: 1.25em;
}
</style>
<script type="text/javascript">
window.onload = init;
 
function init()
{
  obj = document.getElementById("message");
 
  // get width of message
  var clone = obj.cloneNode(true);
  document.body.appendChild(clone);
  totalWidth = clone.offsetWidth;
  document.body.removeChild(clone);
 
  // get width of scroller
  start = document.getElementById("scroller").offsetWidth;
 
  // start message on right-hand side of scroller
  horizPos = start;
 
  setInterval("scroll();", 25);
}
 
function scroll()
{
  horizPos = (horizPos == -1 * (totalWidth -1)) ? start: (horizPos - 1) % totalWidth;
  obj.style.marginLeft = horizPos + "px";
 
}
</script>
</head>
 
<body>
<div id="scroller">
<span id="message"><%=sText%></span>
</div>
</body>
</html>

Open in new window

Avatar of edrz01

ASKER

When I try this code in my masterpage I get the following error:

Pasted"

<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFS = oFSO.OpenTextFile(Server.MapPath(".") & "\test.txt" ,1)
sText = oFS.readall
oFS.Close
set oFS = nothing
set oFSO = nothing
%>




Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1044: Cannot use more than one type in a for, using, fixed, or declaration statement

Source Error:

 

Line 70: <%
Line 71: Dim oFSO, oFS, sText
Line 72: Set oFSO = CreateObject("Scripting.FileSystemObject")
Line 73: Set oFS = oFSO.OpenTextFile(Server.MapPath(".") & "\test.txt" ,1)
Line 74: sText = oFS.readall
 

Source File: c:\Inetpub\SolarWinds\Orion\MasterPage.master    Line: 72
That code is valid ASP by itself, are you declaring oFSO or oFS earlier in the script?
<%
Dim xoFSO, xoFS, sText
Set xoFSO = CreateObject("Scripting.FileSystemObject")
Set xoFS = xoFSO.OpenTextFile(Server.MapPath(".") & "\test.txt" ,1)
sText = xoFS.readall
xoFS.Close
set xoFS = nothing
set xoFSO = nothing
%>
Avatar of edrz01

ASKER

Ok, I think I see the problem. This is being inserted into another app's asp master page which uses C#. I see it is decalred at the top by <%@ Master Language="C#" AutoEventWireup="true" %>

I tried to go to a free vb to c# conversion site but it still didn't work.
ASKER CERTIFIED SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of edrz01

ASKER

Thanks for the assist. Even though the solution didn't work you pointed me in the right direction.
Thanks for the question and the points.