Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help I cant figure this out!!

Status
Not open for further replies.

Jerkycold

IS-IT--Management
Jun 17, 2003
26
0
0
US
i am having trouble with this code. It works when I take out the session variables, but I need them in there. Is there another way to do the session varriables that I am not seeing. Here is the session variables that when I remove it works:

<%
if session(&quot;empid&quot;)=&quot;&quot; then
response.redirect &quot;/peregrine/logon.asp&quot;
end if
%>
<%
empfname = Session(&quot;empfname&quot;)
folder = Session(&quot;empid&quot;)
%>

here is the full code:







<%
Option Explicit
Response.Buffer = True

' This VBScript file creates a local copy of Moreover's news feed in XML
' format and updates it every so many hours. The local cached copy prevents
' unnecessary bandwidth useage to Moreover.

' Author: Craig H. Rettig
' Website:
' Special thanks to Peter A. Bromberg, and his article at Egghead Cafe,
' &quot;Building a Customizable Server-Side Cached Scrolling XML Newsfeed Display&quot;
' URL:
' CONFIG:
Dim sXMLDataDir, nHoursToRefresh, sDefaultCategory

' 1) Where you want the downloaded XML file to be stored (keep trailing slash).
' Please make sure the IIS Anonymous User has write access to this directory.
sXMLDataDir = Server.MapPath(&quot;.&quot;) & &quot;/news/&quot;

' 2) How many hours the page should be cached for
nHoursToRefresh = 1

' 3) If page is called with no arguments, show news from this category
sDefaultCategory = &quot;Top%20US%20stories&quot;

' 4) If you keep moreover.xsl in a different directory than moreover.asp, edit line 86.

' 5) Change stylesheet on line 158 and/or make any other look & feel configurations.

' 6) That should be it!

' This function retrieves the Moreover news feed from Moreover's site
' and saves it to a local file.
Function GetMoreoverXML(ByVal sCategory, ByVal sXMLDataFile)
Dim sChoice, sSource, objHTTP, sArticleList, sOut, oTS, oFSO, i

' Address of Moreover XML feed
sSource= &quot; & sCategory & &quot;&o=xml&quot;

Set objHTTP = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)
Set oFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
objHTTP.Open &quot;GET&quot;, sSource, False
objHTTP.Send

sArticleList = objHTTP.ResponseBody
Set objHTTP = Nothing
sOut = &quot;&quot;

' Decode downloaded result (which is an array of unsigned bytes)
' in order to be able to write the results as plain text
For i = 0 To UBound(sArticleList)
sOut = sOut & ChrW(AscW(Chr(AscB(MidB(sArticleList, i + 1, 1)))))
Next

' Fix some Moreover formatting issues the MSXML parser doesn't like
sOut = Replace (sOut, &quot;encoding=&quot;&quot;iso-8859-1&quot;&quot;&quot;, &quot;&quot;)
sOut = Replace(sOut, &quot;<!DOCTYPE moreovernews SYSTEM &quot;&quot; &quot;&quot;)

Set oTS = oFSO.CreateTextFile(sXMLDataFile, True)
oTS.Write sOut
oTS.Close
Set oTS = Nothing
Set oFSO = Nothing
GetMoreoverXML = True
End Function


' This function applies the moreover.xsl stylesheet to
' the moreover.xml file and returns formatted HTML.
Function sShowNews(ByVal sXMLDataFile)
Dim objXML, objXSL

' Create an instance of the DOM object
Set objXML = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
Set objXSL = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
objXSL.Async = False

' Load the XML newsfeed into the objXML object
objXML.Load(sXMLDataFile)

' Load the XSL stylesheet into the objXSL object
objXSL.Load(Server.MapPath(&quot;.&quot;) & &quot;/moreover.xsl&quot;)

' Check for errors in the XSL
If (objXSL.ParseError.ErrorCode = 0) Then
' Parse the XML data with the XSL file
sShowNews = objXML.TransformNode(objXSL)
Else
' If an error occurs, report it
sShowNews = &quot;Error: &quot; & objXSL.ParseError.Reason & &quot;<br /> URL:&quot; & objXSL.URL
End If

Set objXSL = Nothing
Set objXML = Nothing
End Function


' Main display function
Dim sCategory, objFSO, fNewsFile, dLastSync, bGotFile, sXMLFile

' Which category to show?
If Request.QueryString(&quot;cat&quot;) = &quot;&quot; Then
sCategory = sDefaultCategory
sCategory = Replace(sCategory, &quot;%20&quot;, &quot; &quot;)
Else
sCategory = Request.QueryString(&quot;cat&quot;)
End If

bGotFile = False

Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

' Format the filename of datafile
sXMLFile = LCase(sCategory) & &quot;.xml&quot;
sXMLFile = Replace(sXMLFile, &quot;:&quot;, &quot;&quot;) ' Strip out illegal/ugly characters
sXMLFile = Replace(sXMLFile, &quot;/&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;&&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;?&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;\&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;;&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;=&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;@&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;,&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;&quot;&quot;&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot;'&quot;, &quot;&quot;)
sXMLFile = Replace(sXMLFile, &quot; &quot;, &quot;_&quot;)
sXMLFile = sXMLDataDir & sXMLFile

' Check if XML file exists
If Not objFSO.FileExists(sXMLFile) Then
bGotFile = GetMoreoverXML(sCategory, sXMLFile)
dLastSync = Now()
Else
' Check if file is more than nHoursToRefresh hours old
Set fNewsFile = objFSO.GetFile(sXMLFile)
dLastSync = fNewsFile.DateLastModified
Set fNewsFile = Nothing
If DateDiff(&quot;h&quot;, dLastSync, Now()) >= nHoursToRefresh Then
bGotFile = GetMoreoverXML(sCategory, sXMLFile)
dLastSync = Now()
Else
bGotFile = True
End If
End If
Set objFSO = Nothing
%>
<%
if session(&quot;empid&quot;)=&quot;&quot; then
response.redirect &quot;/peregrine/logon.asp&quot;
end if
%>
<%
empfname = Session(&quot;empfname&quot;)
folder = Session(&quot;empid&quot;)
%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>


<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName==&quot;Netscape&quot;)&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a.indexOf(&quot;#&quot;)!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href=&quot;../images/pef.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<link href=&quot;file://///Pacific/Inetpub/ rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
</head>

<body bgcolor=&quot;#CCCCCC&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot; onLoad=&quot;MM_preloadImages('file://///Pacific/Inetpub/<TABLE width=100% border=0 align=&quot;center&quot; cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<!-- row 01 -->
<TD bgcolor=&quot;#C9C37F&quot;><div align=&quot;center&quot;> <img src=&quot;file://///Pacific/Inetpub/ width=&quot;134&quot; height=&quot;62&quot;></div></TD>
</TR>
</TBODY>
</TABLE>
<table width=&quot;100%&quot; border=&quot;0&quot; bgcolor=&quot;#7C2230&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;7%&quot;><a href=&quot;loui.asp&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image6','','file://///Pacific/Inetpub/ src=&quot;file://///Pacific/Inetpub/ name=&quot;Image6&quot; width=&quot;70&quot; height=&quot;13&quot; border=&quot;0&quot;></a></td>
<td width=&quot;7%&quot;><font color=&quot;#FF0000&quot;><a href=&quot;1003/prequal.asp&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image4','','file://///Pacific/Inetpub/ src=&quot;file://///Pacific/Inetpub/ name=&quot;Image4&quot; width=&quot;70&quot; height=&quot;13&quot; border=&quot;0&quot;></a></font></td>
<td width=&quot;6%&quot;><a href=&quot;logoff.asp&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Image5','','file://///Pacific/Inetpub/ src=&quot;file://///Pacific/Inetpub/ name=&quot;Image5&quot; width=&quot;70&quot; height=&quot;13&quot; border=&quot;0&quot;></a></td>
<td width=&quot;75%&quot;> </td>
<td width=&quot;5%&quot;> </td>
</tr>
</table>
<table width=&quot;100%&quot; height=&quot;478&quot; border=&quot;0&quot; bgcolor=&quot;#FFFFFF&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;89%&quot; height=&quot;474&quot; valign=&quot;top&quot; bgcolor=&quot;#FFFFFF&quot;>
<div align=&quot;center&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<!--DWLayoutTable-->
<tr>
<td height=&quot;23&quot; colspan=&quot;5&quot;><div align=&quot;center&quot;><a href=&quot; · <a href=&quot; ·
<a href=&quot; · <a href=&quot;file://///Pacific/Inetpub/ · <a href=&quot;file://///Pacific/Inetpub/ Search</a><br>
<a href=&quot; · <a href=&quot;file://///Pacific/Inetpub/ Search</a> · <a href=&quot;file://///Pacific/Inetpub/ Search</a>
<cfif #currentcompanyid# is 80>
</cfif>
</div></td>
</tr>
<tr>
<td width=&quot;157&quot; height=&quot;83&quot;> </td>
<td width=&quot;120&quot;> </td>
<td width=&quot;311&quot;> </td>
<td width=&quot;273&quot; valign=&quot;bottom&quot;>
<%
If bGotFile = True Then
Response.Write sShowNews(sXMLFile)
Else
Response.Write &quot;<p><strong>There was an error retrieving the news feed.</strong></p>&quot;
End If
%>
</td>
<td width=&quot;144&quot;> </td>
</tr>
<tr>
<td height=&quot;168&quot;><font color=&quot;#FF0000&quot;> </font></td>
<td colspan=&quot;2&quot; valign=&quot;top&quot;><table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td><font size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>Welcome
<%=Session(&quot;empfname&quot;)%> <%=Session(&quot;emplname&quot;)%> </strong></font></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td><p><font size=&quot;-2&quot;><strong>What would you like to do?</strong></font></p></td>
</tr>
</table>
<table width=&quot;84%&quot; border=&quot;0&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;409&quot; height=&quot;114&quot; valign=&quot;top&quot;> <blockquote>
<p><strong><font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><font size=&quot;-7&quot;>•</font>
<a href=&quot;../Calendar/default.asp&quot; target=&quot;_self&quot;>Check
Leads </a></font></strong><strong><font size=&quot;-1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><br>
<font size=&quot;-7&quot;>•</font> <a href=&quot;../Calendar/default.htm&quot; target=&quot;_self&quot;>Check
Pipeline</a><br>
<font size=&quot;-7&quot;>•</font> <a href=&quot;1003/prequal.asp&quot; target=&quot;_self&quot;>Prequal</a>
<br>
<font size=&quot;-7&quot;>•</font> <a href=&quot;1003/1003.asp&quot; target=&quot;_self&quot;>Loan
Application</a><br>
</font></strong></p>
</blockquote></td>
</tr>
</table></td>
<td valign=&quot;top&quot;><font size=&quot;1&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>
<span class=&quot;ip&quot;><font size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>IP</strong></font></span>:
<font size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><strong>
<%Response.Write(Request.ServerVariables(&quot;remote_addr&quot;))%>
<br>
<br>
<%
response.write(&quot;Todays Date: &quot;)
response.write(&quot;<br />&quot;)
response.write(FormatDateTime(date(),vblongdate))
%>
<br>
<br>
</strong></font> </strong></font> </td>
<td valign=&quot;top&quot;> </td>
</tr>
</table>
</div></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot; bgcolor=&quot;#000000&quot;>
<tr>
<td width=&quot;1%&quot; bgcolor=&quot;#000000&quot;> </td>
<td width=&quot;99%&quot; height=&quot;72&quot; bgcolor=&quot;#000000&quot;><p> </p>
<h6> </h6>
<font color=&quot;#FFFFFF&quot; size=&quot;-2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Copyright
© 2003 • Pacific Eagle Financial Incorporated | Privacy Information
| Legal</font></td>
</tr>
</table>
</body>
</html>



Thanks
 
That's a lot of code. How about explaining what isn't working. Are you receiving an error message? Do the variables never equal anything? What -- specifically -- is not ok now?
 
I am getting this error:

Error Type:
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'empfname'

When I take out my session variables:

<%
if session(&quot;empid&quot;)=&quot;&quot; then
response.redirect &quot;/peregrine/logon.asp&quot;
end if
%>
<%
empfname = Session(&quot;empfname&quot;)
folder = Session(&quot;empid&quot;)
%>



It works, but I need these variables.
 
The first line of your code is &quot;Option Explicit&quot;. That means that you're telling ASP that you will specifically dimension every variable you use. No where in your code are you dimensioning it, so you need:
Code:
Dim empfname
somewhere in your code before you reference it for the first time. The same is true of &quot;folder&quot;, as I don't see it dimensioned anywhere.

That or you can remove the &quot;Option Explicit&quot; line. It's better programming form (and reduces bugs), though, to leave it in and simply dimension all of your variables before you use them.
 
Oh, and to be clear, the error has nothing at all to do with sessions. The error just happens to go away because eliminating the session code also eliminates the real error.
 
you have specified option explicit in the beginning of the page, if you remove that the code will work OR

[smile]

dim empfname
 
Dreamweaver huh? you might want to contact dreamweaver for support.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top