codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  variable scope problem  key2 at 19:50 on Thursday, February 10, 2005
 

I am new to javascript writing and need a bit of help. I am writing a .jsp web page.

I have a javascript function which is:


var fso;
var e;
var theFiles = new Array();
int fileCounter = 0;
var TristateFalse = 0;
var ForWriting = 2;
var ForReading = 1;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
dataFile = myActiveXObject.GetFile("distPath.dat");
text2 = dataFile.OpenAsTextStream(ForReading, TristateFalse);
filepath = text2.ReadLine( );
text2.Close( );

function findFiles() {
fso = new ActiveXObject("Scripting.FileSystemObject");
e = new Enumerator(fso.GetFolder(filepath).files);
for (e.moveFirst(); ! e.atEnd(); e.moveNext()) {

theFiles[fileCounter] = e.item();
fileCounter++;
}
}

I call the function via onload in the <body onload="findFiles();">

the function works, as I have validated that by adding document.writeln(theFiles[fileCounter]) in the above function and get the output I expect (all the files in the directory pointed to by the distPath.dat file.

my problem is I want to display the
theFiles[fileCounter] array data better so I coded a table as below:

<table border="0" cellspacing="1" cellpadding="2" align="center" width="100%">
<tr align="center" bgcolor="#EEEEEE" valign="top">
<td> Filename </td>
</tr>
<% for (int i=0;i< fileCounter ;i++) { %>
<tr align="center" bgcolor="#FFFFFF">
<td> <%= theFiles %></td>
</tr>
<% } %>
</table>

when loading the page I get these errors:


An error occurred at line: 128 in the jsp file: /passwordAdminViewValidUserIDlist.jsp
Generated servlet error:
fileCounter cannot be resolved

(line 128 is the <% for (int i=0;i< fileCounter ;i++) { %> line)

An error occurred at line: 130 in the jsp file: /passwordAdminViewValidUserIDlist.jsp
Generated servlet error:
theFiles cannot be resolved

(line 130 is the <td> <%= theFiles %></td>
line)

can any one help?

Thanks,
K








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Mouse click coordinates on an ActiveX control?
•  Re: Help: Trouble with z-Index and SELECT lists
•  Iframes and Forms
•  Re: validation of two text fields on a search page
•  Help with Java Script
•  Problem with hash map
•  Re: I want the textbox values should be empty
•  Re: iframe targeting
•  Fullscreen code


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005