edrz01
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?
I am putting this into an ASP page.
Help?
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.Fi leSystemOb ject")
Set oFS = oFSO.OpenTextFile(Server.M apPath("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("m essage");
// 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("s croller"). offsetWidt h;
// 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%></s pan>
</div>
</body>
</html>
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.Fi
Set oFS = oFSO.OpenTextFile(Server.M
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("m
// get width of message
var clone = obj.cloneNode(true);
document.body.appendChild(
totalWidth = clone.offsetWidth;
document.body.removeChild(
// get width of scroller
start = document.getElementById("s
// 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%></s
</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:
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>
ASKER
When I try this code in my masterpage I get the following error:
Pasted"
<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set oFS = oFSO.OpenTextFile(Server.M apPath("." ) & "\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.Fi leSystemOb ject")
Line 73: Set oFS = oFSO.OpenTextFile(Server.M apPath("." ) & "\test.txt" ,1)
Line 74: sText = oFS.readall
Source File: c:\Inetpub\SolarWinds\Orio n\MasterPa ge.master Line: 72
Pasted"
<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.Fi
Set oFS = oFSO.OpenTextFile(Server.M
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.Fi
Line 73: Set oFS = oFSO.OpenTextFile(Server.M
Line 74: sText = oFS.readall
Source File: c:\Inetpub\SolarWinds\Orio
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.Fi leSystemOb ject")
Set xoFS = xoFSO.OpenTextFile(Server. MapPath(". ") & "\test.txt" ,1)
sText = xoFS.readall
xoFS.Close
set xoFS = nothing
set xoFSO = nothing
%>
<%
Dim xoFSO, xoFS, sText
Set xoFSO = CreateObject("Scripting.Fi
Set xoFS = xoFSO.OpenTextFile(Server.
sText = xoFS.readall
xoFS.Close
set xoFS = nothing
set xoFSO = nothing
%>
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.
I tried to go to a free vb to c# conversion site but it still didn't work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
<%
Dim oFSO, oFS, sText
Set oFSO = CreateObject("Scripting.Fi
Set oFS = oFSO.OpenTextFile(Server.M
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</
</nobr></span>
With:
<span id="divText"><%=sText%></s
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.