Solved

Write to a text file.

Posted on 1998-09-02
8
164 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now