• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

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?
0
edrz01
Asked:
edrz01
  • 5
  • 4
1 Solution
 
ddrudikCommented:
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:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21310994.html

Finally, replace:
<span id="divText">
<nobr>crusin'... on a Sunday afternoon...to
<a id="link" href="http://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.
0
 
edrz01Author Commented:
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>
0
 
ddrudikCommented:
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

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
edrz01Author Commented:
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
0
 
ddrudikCommented:
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
%>
0
 
edrz01Author Commented:
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.
0
 
ddrudikCommented:
Can't help there, just providing a solution from an ASP perspective.
0
 
edrz01Author Commented:
Thanks for the assist. Even though the solution didn't work you pointed me in the right direction.
0
 
ddrudikCommented:
Thanks for the question and the points.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now