 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 3rd, 2004, 04:38 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
New Line/Carriage Return
Hi All,
Anyone know how to insert the above into a text file?
cheers
interrupt
__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
|
|

October 3rd, 2004, 04:42 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
How are you creating the file?
In JavaScript you need \n for newline and \r for carriage return. I just use \n unless it's a very specific format.
--
Joe
|
|

October 3rd, 2004, 04:49 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe,
\n did the trick, but I've run into a different problem now. I need to purge the contents of the textfile I'm writing to after it hits ten lines. Can you force the input past EOF then use an error handler?
Any help would be much appreciated.
|
|

October 3rd, 2004, 05:00 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
How are you creating the file?
--
Joe
|
|

October 3rd, 2004, 05:07 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The file isn't created each time, it is constantly there. But here's the code I use to write to it:
<script language = "javascript">
function openText(){
var TristateFalse = 0;
var ForAppending = 8;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
file = myActiveXObject.GetFile("c:\\my file.txt");
text = file.OpenAsTextStream(ForAppending, TristateFalse);
text.Write(document.form1.yourName.value + ": " + document.form1.whatever.value);
text.Close();
}
</script>
|
|

October 3rd, 2004, 05:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Use the writeLine method to add lines, then you don't need to worry about the end-of-line character.
Do you want to append lines until it reaches ten lines and then end the file?
You can check the line count on opening with the line property. If it's greater than ten don't write anything.
--
Joe
--
Joe (Co-author Beginning XML, 3rd edition)
|
|

October 3rd, 2004, 05:54 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, thats what I want to do, 10 lines, purge and then start again. Do you have an example of 'writeLine'?
|
|

October 3rd, 2004, 06:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
|
|
 |