Dear Sir,
Why this code can't be ran in my Internet Explorer?
Am I doing wrong in using ActiveXObjectScripting.FileSystemObject")? -
<html>
-
<head><title>Reading/Writing Text File in Javascript</title>
-
</HEAD>
-
<body>
-
<script language="Javascript">
-
var fso = new ActiveXObject("Scripting.FileSystemObject");
-
var a = fso.CreateTextFile("c:\\testfile.txt", true);
-
a.WriteLine("This is a test.");
-
a.Close();
-
alert("testfile.txt has been created successfully");
-
</script>
-
</body></HTML>
[Please use CODE tags when posting source code. Thanks! --pbmods] 7 2090
I've worked out. Thanks a lot!
Dear Sir,
This code is executable but has wrong array's value.
Can anyone put array's value in the right place?
for example:
list[0,0] = Item001 list[0,0] = A001
list[1,0] = Item002 list[0,1] = B001
list[2,0] = Item003 list[0,2] = C001
list[3,0] = Item004 list[0,3] = D001
list[4,0] = Item005 list[0,4] = E001
stocklist.txt:
Item001|A001|99|A002|98
Item002|B001|97|B002|96
Item003|C001|95|C002|94
Item004|D001|93|D001|92
Item005|E001|91|E002|90
stocklist.htm: -
1.<html>
-
2.<head><title>JavaScript Example</title>
-
3.</HEAD>
-
4.<script language=javascript>
-
5.var list = new Array();
-
6.var i = 0;
-
7.var j = 0;
-
8.function ReadFromFile(){
-
9.var sText = "";
-
10.var fso = new ActiveXObject("Scripting.FileSystemObject");
-
11.var FileObject = fso.OpenTextFile("C:\\stocklist.txt", 1);
-
12.sText = FileObject.readall();
-
13.FileObject.close();
-
14.var CR = String.fromCharCode(13);
-
15.lineData = sText.split(CR);
-
16.var transdata = "";
-
17.do
-
18.{address = lineData[i].split("|");
-
19. for (j=0; j<5; j++)
-
20. {
-
21. transdata = address[j];
-
22. list[i,j] = transdata;
-
23. }
-
24. i=i+1;
-
25.}while(i==5);
-
26.document.write(p[4,0]+p[4,1]+p[4,2]+p[4,3]+p[4,4]+",");
-
27.document.write(p[3,0]+p[3,1]+p[3,2]+p[3,3]+p[3,4]+",");
-
28.document.write(p[2,0]+p[2,1]+p[2,2]+p[2,3]+p[2,4]+",");
-
29.document.write(p[1,0]+p[1,1]+p[1,2]+p[1,3]+p[1,4]+",");
-
30.document.write(p[0,0]+p[0,1]+p[0,2]+p[0,3]+p[0,4]+",");
-
31.}
-
32.</script>
-
33.<body>
-
34.<INPUT onclick=ReadFromFile() type=button value="ReadFromFile">
-
35.</body></HTML>
-
Any help will be very appreciated.
Fuji, please use CODE tags when posting source code. See the REPLY GUIDELINES box on the right side of the page next time you post.
[Thanks! Code Tags will be used next time. Does anyone know how to put correct value in array? Please see post code.
-
<html>
-
<head><title>JavaScript Example</title>
-
</HEAD>
-
<script language=javascript>
-
var list = new Array();
-
var i = 0;
-
var j = 0;
-
function ReadFromFile(){
-
var sText = "";
-
var fso = new ActiveXObject("Scripting.FileSystemObject");
-
var FileObject = fso.OpenTextFile("C:\\stocklist.txt", 1);
-
sText = FileObject.readall();
-
FileObject.close();
-
var CR = String.fromCharCode(13);
-
lineData = sText.split(CR);
-
var transdata = "";
-
do
-
{address = lineData[i].split("|");
-
for (j=0; j<5; j++)
-
{
-
transdata = address[j];
-
list[i,j] = transdata;
-
}
-
i=i+1;
-
}while(i==5);
-
document.write(list[4,0]+list[4,1]+list[4,2]+list[4,3]+list[4,4]+",");
-
document.write(list[3,0]+list[3,1]+list[3,2]+list[3,3]+list[3,4]+",");
-
document.write(list[2,0]+list[2,1]+list[2,2]+list[2,3]+list[2,4]+",");
-
document.write(list[1,0]+list[1,1]+list[1,2]+list[1,3]+list[1,4]+",");
-
document.write(list[0,0]+list[0,1]+list[0,2]+list[0,3]+list[0,4]+",");
-
}
-
</script>
-
<body>
-
<INPUT onclick=ReadFromFile() type=button value="ReadFromFile">
-
</body></HTML>
-
Heya, Fuji.
What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Dear Sir,
What do you want your code to do? Give an example.
In this example, I want this code to do that is just like this.
data2[0,0] = array00
data2[0,1] = array01
data2[0,2] = array02
data2[0,3] = array03
What is your code doing that you don't want it to do? Give an example.
data2[0,0] = array10
data2[0,1] = array11
data2[0,2] = array12
data2[0,3] = array13
What is your code *not* doing that it is supposed to? Give an example.
After runnung this code in IE, "document.write(data2[0,0] + data2[0,1] + data2[0,2] + data2[0,3] + data2[0,4]);" prints out the result is not supposed to have.
What I want is
data2[0,0] = array00
data2[0,1] = array01
data2[0,2] = array02
data2[0,3] = array03
What do not I want is
data2[0,0] = array10
data2[0,1] = array11
data2[0,2] = array12
data2[0,3] = array13
<html>
<head><title>JavaScript Example</title>
</HEAD>
<script language=javascript>
data1 = new Array();
data2 = new Array();
function javascriptarray(){
data1[0] = "array:"+0+0;
data1[1] = "array:"+0+1;
data1[2] = "array:"+0+2;
data1[3] = "array:"+0+3;
data2[0,0] = data1[0];
data2[0,1] = data1[1];
data2[0,2] = data1[2];
data2[0,3] = data1[3];
data1[0] = "array:"+1+0;
data1[1] = "array:"+1+1;
data1[2] = "array:"+1+2;
data1[3] = "array:"+1+3;
data2[1,0] = data1[0];
data2[1,1] = data1[1];
data2[1,2] = data1[2];
data2[1,3] = data1[3];
document.write(data2[0,0] + data2[0,1] + data2[0,2] + data2[0,3] + data2[0,4]);
}
</script>
<body>
<INPUT onclick=javascriptarray() type=button value="arraycheck">
</body></HTML>
Thanks a lot! Everyone.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Santah |
last post by:
hi
I'm new to C++
and I'm currently working on Visual C++ 6.0
I'm trying to open a text file, and read some data from it
part of the text file looks like this:
--------
|
by: Steve |
last post by:
OK, I know I can't read a file with JavaScript, but I see references
that I can use the filesystemobject which is part of vb script. Can I
embed vb script in HTML?
I am writing a program for...
|
by: Robby Bankston |
last post by:
I'm working on some code and am running into brick walls. I'm trying
to write out Javascript with Javascript and I've read the clj Meta FAQ
and didn't see the answer, read many similar posts (with...
|
by: Jeevan |
last post by:
Hi,
I have an array of data (which I am getting from a socket connection).
I am working on a program which acts on this data but the program is
written to work on data from a file (not from an...
|
by: Sivaraj G via .NET 247 |
last post by:
We created a unicode file using java application. It usesmethods like writeUTF(), writeInt() of java.io.DataOutputStreamclass to write the content of the file. We are able to read datausing...
|
by: Raghu |
last post by:
Is it possible to write a new file and after writing few bytes, is it
possible to read from it from another file stream while write continues? Is
there another steam for this type of operation?
...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: Clive Green |
last post by:
Hello peeps,
I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and
writing MP3 tags). I have been using PHP on the command line (Mac OS X
Unix shell, to be precise), and am...
|
by: HardySpicer |
last post by:
I have a cvs data file orbit.csv and found this code.
function ReadFile()
{
var fso, f1, ts, s;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f =...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |