fbolavidez Posted September 18, 2007 Share Posted September 18, 2007 Gudpm!Somebody help me about my problem in text files..whats wrong in my code?how can i know the content on the text file, whether 0 or 1?if the files contain 0, it will alert('File contain zero') else alert('File doesn't contain any zero') ?Thanks for any help....:-)here is my code: function ReadFile(objRow){ var filename = 'c:\\B64210189 0001.txt' var fso, ForReading; ForReading = 1; fso = new ActiveXObject('Scripting.FileSystemObject'); file = fso.OpenTextFile(filename, ForReading, false); var fn = file.ReadAll(); if(fn != "1" && fn == "0")// if the file contain zero.. { alert('File contains zero!') rowColor = 'red'; } else { alert('File doesnt contain zero') rowColor = 'green'; } objRow.bgColor = rowColor; file.Close(); } Link to comment Share on other sites More sharing options...
aspnetguy Posted September 18, 2007 Share Posted September 18, 2007 what about it not working? what errors do you get? Link to comment Share on other sites More sharing options...
fbolavidez Posted September 19, 2007 Author Share Posted September 19, 2007 what about it not working? what errors do you get?good day! thanks for your reply...Actually its working but there's something wrong in my condition.my if else condition in my code in not working..that's my problem!how can i detect if the content of the file has 0 or 1? :-) Link to comment Share on other sites More sharing options...
zppblood Posted September 19, 2007 Share Posted September 19, 2007 Your conditional says if it has a zero AND doesn't contain one where both statements must be true to run that code. So maybe try replacing && with ||, or create an if (fn=="0") { // some code}elseif (fn=="1") { // some code}Hope this helps. Link to comment Share on other sites More sharing options...
fbolavidez Posted September 19, 2007 Author Share Posted September 19, 2007 Your conditional says if it has a zero AND doesn't contain one where both statements must be true to run that code. So maybe try replacing && with ||, or create an if (fn=="0") { // some code}else if (fn=="1") { // some code}Hope this helps.hi! i try the code but it's not working too.the content of the file is here:1110111111 1111101111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111101111 1111111111 11111111111111110111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111111111 1111101111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111110111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111101111 11111111111111111111 1111111111 1111111111 1111111111 11111111111111111111 1111111111 1111111111 1111111111 1111111111then when i run my program it should alert('File contains zero!').any sample code to run this? thanks.... Link to comment Share on other sites More sharing options...
justsomeguy Posted September 19, 2007 Share Posted September 19, 2007 You're not checking if the file contains a zero, you are checking if the file is a zero. You can use the String.indexOf function to check if a certain character exists in a string.http://www.w3schools.com/jsref/jsref_indexOf.asp Link to comment Share on other sites More sharing options...
fbolavidez Posted September 20, 2007 Author Share Posted September 20, 2007 You're not checking if the file contains a zero, you are checking if the file is a zero. You can use the String.indexOf function to check if a certain character exists in a string.http://www.w3schools.com/jsref/jsref_indexOf.asp gud day! can you give me a sample code for that? thanks! Link to comment Share on other sites More sharing options...
fbolavidez Posted September 20, 2007 Author Share Posted September 20, 2007 gud day! can you give me a sample code for that? thanks!i use indexOf in my code but its not working, too!can you give me sample working code for that plz!!!! thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted September 20, 2007 Share Posted September 20, 2007 if (fn.indexOf("0") == -1) { Link to comment Share on other sites More sharing options...
fbolavidez Posted September 24, 2007 Author Share Posted September 24, 2007 i use indexOf in my code but its not working, too!can you give me sample working code for that plz!!!! thanks!Good Day!thanks! i got it, anyway i have last question.. how can i put this into arraylist? put content of the file into arraylist?? pls....!!! thnx..:-) Link to comment Share on other sites More sharing options...
justsomeguy Posted September 24, 2007 Share Posted September 24, 2007 Well, I guess you can do this:var ar = new Array(your_file_text);That will make an array where the first element is the contents of the file text variable. Link to comment Share on other sites More sharing options...
fbolavidez Posted September 25, 2007 Author Share Posted September 25, 2007 Well, I guess you can do this:var ar = new Array(your_file_text);That will make an array where the first element is the contents of the file text variable.Ok! thanks a lot! how about passing the value of arraylist from jsp to javascript arraylist? :-) thanks again! Link to comment Share on other sites More sharing options...
justsomeguy Posted September 25, 2007 Share Posted September 25, 2007 An array doesn't have a value, it is a collection of values. If you want to pass a complex data structure like an array between languages you will need to serialize it so that both languages can understand it. JSP might be able to serialize an array that Javascript can unserialize and understand, but if not then you will need to build your own serializer in JSP and your own unserializer in Javascript to encode and decode the array. Link to comment Share on other sites More sharing options...
fbolavidez Posted September 26, 2007 Author Share Posted September 26, 2007 An array doesn't have a value, it is a collection of values. If you want to pass a complex data structure like an array between languages you will need to serialize it so that both languages can understand it. JSP might be able to serialize an array that Javascript can unserialize and understand, but if not then you will need to build your own serializer in JSP and your own unserializer in Javascript to encode and decode the array.thanks! how can i do that? any sample code..thanks a lot for your help! :-) Link to comment Share on other sites More sharing options...
justsomeguy Posted September 26, 2007 Share Posted September 26, 2007 Learn about serialization here:http://en.wikipedia.org/wiki/SerializationIf the languages don't share an interface that you can use, then you'll have to think about a format that you can convert the array to in one language where you can convert it back to an array in another language. You can turn the array into a comma-separated list of values, for example, assuming that you can guarantee a comma won't appear in any element. If the array is multi-dimensional, then the format for representing it will become a lot more complex. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.