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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help with java script, for calling from a file.

Status
Not open for further replies.

lvr5555

Programmer
Oct 15, 2008
13
US
Hai all,

I need some help with java script. I am fairly new to js, so can you please help me out.

Here is my issue..

I am writing a java script where it need to check for some thing from a .txt file. i have a .txt file where it has the following data(P.S it has comma seperated values)

The file text is in this way...(I have saved as abc.txt)

A,B,C,D,E,F,G,H,I,J
1,ABC,XYZ,YOW-YVR,D,CXR11,Use this for this pair,1,2,3,4
2,ABC,XYZ,YVR-YYZ,D, --,No Message,1,2,3,4
3,ABC,XYZ,YUL-YYZ,D,CROC07,Use after this,1,2,3,4
4,ABC,XYZ,YYC-YYZ,D,CXR13,Use this for this pair2,1,2,3,4
5,ABC,XYZ,YOW-YYZ,D,CROC07,Use after this,1,2,3,4
6,ABC,XYZ,YHZ-YOW,D,CXR13,Use this for this pair3,1,2,3,4
7,ABC,XYZ,LHR-YYZ,I,CXR13,Use this for this pair4 ,1,2,3,4
8,ABC,XYZ,YEG-YYZ,D,CXR13,Use this for this pair5,1,2,3,4
9,ABC,XYZ,YEG-YOW,D,CXR13,Use this for this pair8,1,2,3,4
10,ABC,XYZ,YOW-YYC,D,CXR13,Use this for this pair3,1,2,3,4

So in the first line it has the description for each field. In the first line we have 10 fields A to J
From the second line we have the actual data in that. We have 10 fields from there too. I have almost 500 lines in this way.
as you can see all the fields(10) from the second line are in the same format and fields 2 and 3 (ABC,XYZ)are always same.
And the last 4 fields 1,2,3,4 may be same or different, but my requirement does not contain these fields.
In this what i need is, i give two values, lets say val1 and val2. So in this java script it should check for val1= first 3 letters from the field 3 in the txt file(abc.txt) i.e for the first line it is YOW and then check for val2= last 3 letters from field 3 from the txt file (abc.txt)i.e for the first line it is YVR.
If it satisfies then it should print the filed 6 i.e for the first line it is : Use this for this pair.

So in this java script it should check for all the lines in the text file for any possible combinations. And all the fields are seperated by commas, and the code should ommit checking for the first line, as it is not required.

Hope you understand my point,
please some one can help me.
 
This sounds a LOT like a homework assignment.

Does the file reside on the server or on the client computer? If on the server, you'll have to use some kind of server-side technology, like ASP, ASP.NET, PHP, ColdFusion, etc. You can write classic ASP using Javascript, and that's what I've always used.

If it resides on the client computer, you'll need to use the File Scripting object. This would be Internet Explorer only if you're using a browser to run the Javascript.

Lee
 
hai lee,

Thanks for the quick reply, I am working now, i am past the school days but never used in the school :).So thought some one could help me with any ideas.

Regarding the file, I have saved the file in my local folder, so I just need to call every time and check each line for the entered pair.

 
[tt]//as givens
[green]var sdir="c:\\xyx"; //directory where the csv file resides
var sfile="abc.txt"[/green]

var conn=new ActiveXObject("Adodb.Connection");
var sconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+sdir+";"+"Extended Properties=\"text;HDR=YES;FMT=Delimited\";";
conn.open(sconn);

//as input
[green]var var1="YOW";
var var2="YVR";[/green]

var ssql="SELECT * FROM "+sfile+" WHERE D like '"+var1+"%"+var2+"';";
var rs=conn.execute(ssql);
if (!rs.eof) {
while (!rs.eof) {
for (var i=0;i<rs.fields.count;i++) {
//do thing with fields
//rs.fields(i).value
//named column can be accessed such as
//rs.field("D").value or rs("D").value
}
rs.MoveNext();
}
} else {
//does not find any record that match
//do some thing else
}
rs.close();
conn.close();
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top