Solved

Write to a text file.

Posted on 1998-09-02
8
167 Views
Last Modified: 2010-04-30
What is the simplest way to write to a text file.  This is my routine:
Open "C:\windows\system\settings.txt" For Output As #1
Write #1, Something
 Close #1

I want to be able to write to the next available line with out deleting  the previous lines.  Also, I would like to know how to add a string to the right of any line I choose.

Thank you .
0
Comment
Question by:checkout
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1432551
        nPrintOut = FreeFile
         Open sPSOut For Binary Access Write As #nPrintOut
         
         ' *** Add lines

         ' *** Close output file
         Close #nPrintOut

0
 
LVL 14

Expert Comment

by:waty
ID: 1432552
NB : I forgot to show you sample of writing :

       Put #nPrintOut, , "startrub" & NEW_LINE
       Put #nPrintOut, , "(" & sItem & ") putpgnum" & NEW_LINE
.
0
 

Author Comment

by:checkout
ID: 1432553
Hi Waty,

I don't doubt that your answer may work, but I am not sure how to use it.  Remember this file already exists it may have data in it.  Where you say add lines, my question is how?  I'm not really looking for theory, I need some example.Can you show me a working example, and I will give you the points.


Thank you
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1432554
As it is Text file, use the following code. It works well, I have just tested it.

   nPrintOut = FreeFile
   Open "d:\c.txt" For Append Access Write As #nPrintOut
   
   Print #nPrintOut, "Koko 1"
   Print #nPrintOut, "Koko 2"
       
   ' *** Close output file
   Close #nPrintOut

0
 

Author Comment

by:checkout
ID: 1432555
I got your example, but it deleted the line that was in there and put this one inplace:

  startrub () putpgnum


Whats wrong?

Thanks

0
 

Author Comment

by:checkout
ID: 1432556
Thank you.
0
 
LVL 14

Expert Comment

by:waty
ID: 1432557
Try my second sample, it is better. The first one opened the file as binary. I do like this here at work.
0
 
LVL 1

Expert Comment

by:rayford
ID: 1432558
How this old Basic method of IO works is you can use either Print your output file line by line which is a variable length record using the EOL CR-LF as a record separator OR you can use Binary Random access which if I'm not mistaken requires a fixed record length.  So for you to be able to INSERT "records" you would need to waste some space by padding your output lines and switch over from the old PRINT and LINE INPUT technique to the BINARY RANDOM access RECORD method.  Decide how big the largest text line will be and simply space fill all records to this larger size abd you should have no trouble working with inserting and editing records then.  I've got some sample code and help from the VB books Online etc if you need it.  You may also want to simply look into using a database which will allow for better inserting and sorting of your records but this RANDOM access is the best for editing (adding to the right as you say) of existing records and appending both.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question