Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old October 3rd, 2004, 04:38 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
  #2 (permalink)  
Old October 3rd, 2004, 04:42 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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
  #3 (permalink)  
Old October 3rd, 2004, 04:49 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

  #4 (permalink)  
Old October 3rd, 2004, 05:00 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How are you creating the file?

--

Joe
  #5 (permalink)  
Old October 3rd, 2004, 05:07 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>
  #6 (permalink)  
Old October 3rd, 2004, 05:48 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #7 (permalink)  
Old October 3rd, 2004, 05:54 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, thats what I want to do, 10 lines, purge and then start again. Do you have an example of 'writeLine'?

  #8 (permalink)  
Old October 3rd, 2004, 06:27 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Scripting Runtime Reference

--

Joe


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for a Carriage return darkhalf Classic ASP Databases 2 November 5th, 2007 06:15 AM
insert carriage return darkhalf Javascript 0 April 10th, 2007 02:42 PM
about carriage return... edu1980 XSLT 1 July 5th, 2006 04:11 AM
HELP Inserting Carriage Return orangem Classic ASP Databases 8 July 5th, 2004 08:36 PM
Line Break/Carriage Return in URL lian_a Classic ASP Basics 6 June 24th, 2004 03:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.