File open for input and output

Posted on 2009-04-01
Last Modified: 2012-05-06
In VB6 I could open a file for input then open a file for output and then write any part of a line from the input file to the output file see sample below.  

I want to do exactly the same thing in,  I have found example which show me how to read a file and write static text to a file but I can not find any help on how to write a string from the file I just opened and read.

Any help greatlt appreciated.
Private Sub Form_Load()

Open "C:\Users.ini" For Input As #1

Open "C:\StationID.ini" For Input As #2

Do While EOF(2) = False And EOF(1) = False

Open "C:\Config.NT" For Output As #3

Line Input #2, Temp1$

Print #3, "dos = high, umb"

Print #3, ";device=%SystemRoot%\system32\himem.sys"

Print #3, ";device=%SystemRoot%\system32\emm386.exe"

Print #3, "EMM =RAM"

Print #3, "FILES=80"

Print #3, "device=C:\utils\netid.exe /d:" & Temp1$

Print #3, ""

Print #3, "REM Added by Pervasive.SQL V8 install:"


Close #3

Line Input #1, Temp$

FileSystem.MkDir "C:\WorkStationIDs\" & Temp$

FileSystem.FileCopy "C:\Config.NT", "C:\WorkStationIDs\" & Temp$ & "\Config.NT"


Unload Me

End Sub

Open in new window

Question by:smasshed
LVL 48

Accepted Solution

jpaulino earned 500 total points
ID: 24040184
In .NET you can use StreamReader and StreamWriter to do that!

        Dim fileName As String = "d:\test.txt"

        Dim fileNameOutput As String = "d:\testOutput.txt"

        Using writer As New IO.StreamWriter(fileNameOutput)

            Using reader As New IO.StreamReader(fileName)

                While Not reader.EndOfStream()

                    Dim result As String = reader.ReadLine()

                    writer.WriteLine(result & " some extra text")

                End While

            End Using

        End Using

Open in new window


Author Closing Comment

ID: 31565338
Easy when you know how, thanks alot.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: (…

911 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

18 Experts available now in Live!

Get 1:1 Help Now