473,725 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FileS ystemObject");
f = fso.OpenTextFil e( Server.MapPath( "orbit.csv" ), ForReading);
return(f.ReadAl l());
}

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 3533
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.FileS ystemObject");
f = fso.OpenTextFil e( Server.MapPath( "orbit.csv" ), ForReading);
return(f.ReadAl l());
}

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 bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Jan 6 '08 #2
On Jan 6, 2:33*pm, HardySpicer <gyansor...@gma il.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.FileS ystemObject");
* * *f = fso.OpenTextFil e( Server.MapPath( "orbit.csv" ), ForReading);
* return(f.ReadAl l());

}

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..oled b 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...@gma il.comwrote:
On Jan 6, 2:33 pm, HardySpicer <gyansor...@gma il.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.FileS ystemObject");
f = fso.OpenTextFil e( Server.MapPath( "orbit.csv" ), ForReading);
return(f.ReadAl l());
}
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..oled b 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...@gma il.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...@gma il.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...@we b.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************ *************** *******@r60g200 0hsc.googlegrou ps.com>.

You should read more thoroughly and be slower to jump to conclusions; that
would avoid such misunderstandin gs.
PointedEars
Jan 6 '08 #8
On Jan 6, 5:42*pm, Thomas 'PointedEars' Lahn <PointedE...@we b.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...@gma il.comwrote:
On Jan 6, 3:48 pm, HardySpicer <gyansor...@gma il.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

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

Similar topics

3
1970
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 using data in a JavaScript cookie in a PHP file. The JavaScript Cookie document.cookie = "order=" + escape("website = " + website + "*" + "sale = " + sale + "*" + "name = " + name + "*" + "addr1 = " + addr1 + "*" + "addr2 =
7
2979
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 manipulate with JSP, and feel that the best way is for the users to have the bulk of the text 'cached' on their machine in a .js file rather than read from a database every time they access. The strings will rarely change. If not, any other...
2
1129
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 following problem. Visitor of a wep page creates some data which will be changed during next subsequent visit of this page. I wanted to store this data in a file on the server side and then read this data at next conection of the corresponding user....
3
1603
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 my file. I only need the data if it begins with a number (numeric) value.
12
2905
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 workstation it works fine, but when I publish the page on our DEV server it doesn't fine the CSV file from the client. Has anyone done this before? If so, how do I do it? I'm new to ASP.net so
1
1328
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: <units> <unit unitName=...> <position time=... lat=... long=.../> <position time=... lat=... long=.../>
7
3838
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 possible to read directly from that file, or would I need the user to upload the file and subsequently read the data from it? In any case, what would be the best and cleaner way to do it? I thank you in advance for any insight on this,
0
8872
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9162
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8069
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6694
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4773
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3211
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2619
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2150
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.