Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

How to append in the txt lines?

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
zzwin
Asked:
zzwin
  • 2
  • 2
2 Solutions
 
mkhaleelrCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
zzwinAuthor Commented:
Is there any way where temp.text  wiil be opened for both input and output, instead of making new temp1.txt file ?  
0
 
zzwinAuthor Commented:
Actually, for not extremely big files this solution is quite OK.
Thanx guys.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now