?
Solved

How to  append in  the txt lines?

Posted on 2005-03-05
5
Medium Priority
?
194 Views
Last Modified: 2010-05-02
I have a big data.txt where lines look
50,70,3,30
85,15,30,5
75,7,90,77
etc
without blank lines. I would like to add  ,50,75,55 at the end of data in every single line so it looks
50,70,3,30,50,75,55
85,15,30,5,50,75,55
75,7,90,77,50,75,55

Any help with this?
0
Comment
Question by:zzwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
mkhaleelr earned 400 total points
ID: 13469436
Private Sub Form_Load()

Open "C:\temp.txt" For Input As #1
Open "c:\temp1.txt" For Output As #2
Do While Not EOF(1)
    Input #1, col1, col2, col3, col4
    Write #2, col1 & "," & col2 & "," & col3 & "," & col4 & ",50,75,55"
Loop
Close #1
Close #2


End Sub

hope it helps,
khaleel
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 13469454
A Slight variation of mkhaleelrs code:

Dim inputLine As String
Open "C:\temp.txt" For Input As #1
Open "c:\temp1.txt" For Output As #2
Do While Not EOF(1)
    Line Input #1, inputLine
    Print #2, inputLine & ",50,75,55"
Loop
Close #1
Close #2
0
 

Author Comment

by:zzwin
ID: 13469471
Is there any way where temp.text  wiil be opened for both input and output, instead of making new temp1.txt file ?  
0
 

Author Comment

by:zzwin
ID: 13469539
Actually, for not extremely big files this solution is quite OK.
Thanx guys.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13470342
Here is another approach for smaller files:

Private Sub Command1_Click()
    Dim ff As Long
    Dim line As Variant
    Dim lines As New Collection
    Dim fileName As String
   
    fileName = "c:\Output.txt"
    If Dir(fileName) <> "" Then
            ff = FreeFile()
        Open fileName For Input As #ff
        Do While Not EOF(ff)
            Line Input #ff, line
            lines.Add line & ",50,75,55"
        Loop
        Close #ff
   
        ff = FreeFile()
        Open fileName For Output As #ff
        For Each line In lines
            Print #ff, line
        Next
        Close #ff
       
        MsgBox "Done"
    Else
        MsgBox fileName, vbCritical, "File Not Found"
    End If
End Sub
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

771 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