473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Reading a data file in JavaScript

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 = fso.OpenTextFile( Server.MapPath("orbit.csv"), ForReading);
return(f.ReadAll());
}

The data file has four columns and the first line maybe something like

1.23,3.45,6.78,2.34

I need access to the second and third column only. Can I use teh above
function - if so how exactly?

Thanks

Hardy
Jan 6 '08 #1
10 3504
HardySpicer wrote:
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 = fso.OpenTextFile( Server.MapPath("orbit.csv"), ForReading);
return(f.ReadAll());
}

The data file has four columns and the first line maybe something like

1.23,3.45,6.78,2.34

I need access to the second and third column only. Can I use teh above
function - if so how exactly?
RTFM:

http://msdn2.microsoft.com/en-us/lib...4s(VS.85).aspx
http://msdn2.microsoft.com/en-us/library/312a5kbt.aspx
http://msdn2.microsoft.com/en-us/lib...dd(VS.85).aspx
http://msdn2.microsoft.com/en-us/lib...6b(VS.85).aspx
http://msdn2.microsoft.com/en-us/lib...fe(VS.85).aspx
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Jan 6 '08 #2
On Jan 6, 2:33*pm, HardySpicer <gyansor...@gmail.comwrote:
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 = fso.OpenTextFile( Server.MapPath("orbit.csv"), ForReading);
* return(f.ReadAll());

}

The data file has four columns and the first line maybe something like

1.23,3.45,6.78,2.34

I need access to the second and third column only. Can I use teh above
function - if so how exactly?

Thanks

Hardy
Do you have some need to do this in JavaScript? Could you elaborate a
little more in what context you will be doing this?

Local file access form a browser is typically a no-no. ActiveX will
only work in IE, and at a minimum the user would be prompted to allow
or deny active x access to the file system.

And I have no idea what the "Server" object referenced here is
'Server.MapPath("orbit.csv")'

As far as accessing the 2nd and third columns, there are many ways
this can be done. You could read the whole file line by line, put each
line into a string, and parse the string using various string
functions, keying on the commas. Since it is a csv file, it can be
probably read in as a dataset, or recordset..oledb comes to mind. At
any rate, I would not use JavaScript for this.
Jan 6 '08 #3
On Jan 7, 10:31 am, Doug Gunnoe <douggun...@gmail.comwrote:
On Jan 6, 2:33 pm, HardySpicer <gyansor...@gmail.comwrote:
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 = fso.OpenTextFile( Server.MapPath("orbit.csv"), ForReading);
return(f.ReadAll());
}
The data file has four columns and the first line maybe something like
1.23,3.45,6.78,2.34
I need access to the second and third column only. Can I use teh above
function - if so how exactly?
Thanks
Hardy

Do you have some need to do this in JavaScript? Could you elaborate a
little more in what context you will be doing this?

Local file access form a browser is typically a no-no. ActiveX will
only work in IE, and at a minimum the user would be prompted to allow
or deny active x access to the file system.

And I have no idea what the "Server" object referenced here is
'Server.MapPath("orbit.csv")'

As far as accessing the 2nd and third columns, there are many ways
this can be done. You could read the whole file line by line, put each
line into a string, and parse the string using various string
functions, keying on the commas. Since it is a csv file, it can be
probably read in as a dataset, or recordset..oledb comes to mind. At
any rate, I would not use JavaScript for this.
Ok I need to plot the GPS orbit of a satellite. I have the data and I
want to use Google Maps. I know how to plot a line in Google Maps no
problem but I need to read the orbit data line by line then plot teh
data. Of course I can do this locally but I want others to get access
and at present the data is only simulated - it will be real at some
point.

I was also unsure how to access the data file: Microsoft gives this

a = fs.OpenTextFile("c:\\testfile.txt", ForAppending, false);

but what does this mean on a server? (ie the path is ??) The data is
on the server and not on my pc. Not worried about acknowledging active-
x btw - that's ok.

Hardy
Jan 6 '08 #4
On Jan 6, 3:48*pm, HardySpicer <gyansor...@gmail.comwrote:
Ok I need to plot the GPS orbit of a satellite. I have the data and I
want to use Google Maps. I know how to plot a line in Google Maps no
problem but I need to read the orbit data line by line then plot teh
data. Of course I can do this locally but I want others to get access
and at present the data is only simulated - it will be real at some
point.

I was also unsure how to access the data file: Microsoft gives this

a = fs.OpenTextFile("c:\\testfile.txt", ForAppending, false);

but what does this mean on a server? (ie the path is ??) The data is
on the server and not on my pc. Not worried about acknowledging active-
x btw - that's ok.

Hardy- Hide quoted text -

- Show quoted text -
Since the file is on a server, an activeX file system object will not
work. It would just try to access the user's system.

You could use a server side script to read the file and parse the
values you need. I know PHP has functions to parse and use CSV files.
This would be an easier way to handle the problem, IMO.

http://us.php.net/fgetcsv

And I'm sure other server side technologies do as well.

You can also use AJAX

http://developer.mozilla.org/en/docs...etting_Started

Jan 6 '08 #5
Doug Gunnoe wrote:
On Jan 6, 3:48 pm, HardySpicer <gyansor...@gmail.comwrote:
>Ok I need to plot the GPS orbit of a satellite. I have the data and I
want to use Google Maps. I know how to plot a line in Google Maps no
problem but I need to read the orbit data line by line then plot teh
data. Of course I can do this locally but I want others to get access
and at present the data is only simulated - it will be real at some
point.

I was also unsure how to access the data file: Microsoft gives this

a = fs.OpenTextFile("c:\\testfile.txt", ForAppending, false);

but what does this mean on a server? (ie the path is ??) The data is
on the server and not on my pc. Not worried about acknowledging active-
x btw - that's ok.
[...]
If you Google idio^W users would ever learn how to quote properly?
Since the file is on a server, an activeX file system object will not
work.
Yes, it will.
It would just try to access the user's system.
It will allow access to the filesystem of the computer it is being created on.

http://msdn2.microsoft.com/en-us/lib...eh(VS.85).aspx
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jan 6 '08 #6
On Jan 6, 4:24*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Yes, it will.
From client side javascript?
Jan 6 '08 #7
Doug Gunnoe wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
>Yes, it will.
By trimming too much, you have been destroying the context of the quoted
text here. Will you ever learn how to quote properly?
From client side javascript?
Nobody aside from you ever stated a restriction of a solution to client-side
JavaScript, let alone JavaScript instead of JScript. In fact, the OP
specifically asked about server-side JScript in
<8e**********************************@r60g2000hsc. googlegroups.com>.

You should read more thoroughly and be slower to jump to conclusions; that
would avoid such misunderstandings.
PointedEars
Jan 6 '08 #8
On Jan 6, 5:42*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
>*Will you ever learn
Probably not.
Nobody aside from you ever stated a restriction of a solution to client-side
JavaScript,
Well if that is the case, all apologies to the OP.

(But I would still consider using something other than J\JavaScript
and a file system object for this.)
Jan 7 '08 #9
On Jan 7, 11:18 am, Doug Gunnoe <douggun...@gmail.comwrote:
On Jan 6, 3:48 pm, HardySpicer <gyansor...@gmail.comwrote:
Ok I need to plot the GPS orbit of a satellite. I have the data and I
want to use Google Maps. I know how to plot a line in Google Maps no
problem but I need to read the orbit data line by line then plot teh
data. Of course I can do this locally but I want others to get access
and at present the data is only simulated - it will be real at some
point.
I was also unsure how to access the data file: Microsoft gives this
a = fs.OpenTextFile("c:\\testfile.txt", ForAppending, false);
but what does this mean on a server? (ie the path is ??) The data is
on the server and not on my pc. Not worried about acknowledging active-
x btw - that's ok.
Hardy- Hide quoted text -
- Show quoted text -

Since the file is on a server, an activeX file system object will not
work. It would just try to access the user's system.

You could use a server side script to read the file and parse the
values you need. I know PHP has functions to parse and use CSV files.
This would be an easier way to handle the problem, IMO.

http://us.php.net/fgetcsv

And I'm sure other server side technologies do as well.

You can also use AJAX

http://developer.mozilla.org/en/docs...etting_Started
Yes I solved the problem in PHP but the map wasn't good enough -I
needed a zoom facility.
I then had the problem of how to combine PHP with Javascript (since
Javascript is used for Google Maps). I am not sure how to do this. I
need to read a line of data then plot. So I need PHP followed by
Javascript then repeat.

Hardy
Jan 7 '08 #10
On Jan 6, 11:47*pm, HardySpicer <gyansor...@gmail.comwrote:
Yes I solved the problem in PHP but the map wasn't good enough -I
needed a zoom facility.
I then had the problem of how to combine PHP with Javascript (since
Javascript is used for Google Maps). I am not sure how to do this. I
need to read a line of data then plot. So I need PHP followed by
Javascript then repeat.

Hardy- Hide quoted text -

- Show quoted text -
If you need to read the file - plot, read the file - plot because the
file is changing after the browser has loaded the page, then something
like AJAX would be a good choice, and plus it uses JavaScript like
Google maps (which is also an AJAX app I think).

But if the orbit.csv file does not change whilst the user has loaded
your page, then PHP can work with google maps, simply by writing
JavaScript vars with php.

For example, and consider this more or less pseudocode, and this can
be done many different ways

<script>
function plotStuff(){
var plotData = [];
for(var i = 0;i<something;i++){ //or some appropriate loop here
plotData[i] = <?php echo some_PHP_function('read the data') ?>;
}

</script>

where some_PHP_function would read the data you want to read.

Of course, there are many different ways to do this, you could read
everything into an array in PHP first, and then for each item in the
array do

plotData[i] = <?php echo plotDataPHP[i] ?>
And again, this is more or less pseudocode, so don't take it
literally, but the general idea will work.

After this, you have your info into javaScript and can do as you
please with it.
Jan 7 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ken | last post by:
I am new to PHP. But this seems like a terrific language. I have been using JavaScript up to now but it looks like I will be changing to PHP. Seems to have more potential. I am confused about...
7
by: Iain Downie | last post by:
Anyone out there know of an easy way to fill a Java ArrayList in a JSP from an array of strings held in a external JavaScript file? We need to load up a large number of strings into the page and...
2
by: Q | last post by:
Hello, I looked through some posting of this group and understood that for JavaScript it is not natural ot read from a file. Isn't that so? If it is a case, what is the best solution for the...
3
by: John | last post by:
How can I tell if a line begins with a number instead of a character? I need to read a text file and some of the data begins with a character which is causing me an issue in reading and uploading...
12
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my...
1
by: bookimal | last post by:
Hi, I'm not sure whether this goes in the XML or the Javascript forum but I guess its more Javascript because I want to read an XML file.. Anyway... I've got an XML file in this form: ...
7
by: L. Ximenes | last post by:
Hello everyone, I know how to parse data from an XML file with Javascript; but what if I would like to parse data from a user-submitted XML file via the " <input type='file'"? Would it be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.