VB6 text file manipulation

I am new to VB6 and need to create a button that will make a change to an entry in a file. There will be three of these buttons. After the changes are made then a fourth will execute a script file that does other things. Does anyone have any sample code that I can use for these buttons?
TCHURCH65Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
What sort of change?
0
VBRocksCommented:
VB6:  Add a reference to the Microsoft Scripting Runtime Library (scrrun.dll) Project / References.  

Then, code like this:
Dim fso as new FileSystemObject
Dim ts as TextStream
Dim inLine as string

'To Read:
set ts = fso.OpenTextFile("c:\temp\myfile.txt", ForReading)
Do
     inLine = ts.ReadLine
     'Process with your line.
Loop Until ts.AtEndOfStream = True
ts.close

'To Write:
set ts = fso.OpenTextFile("c:\temp\myfile.txt", ForWriting)
ts.WriteLine "Cool!"
ts.Close
0
TCHURCH65Author Commented:
I'm getting an error that state "User defined type not defined" and points out this

Dim fso As New FileSystemObject

The file is a router config file and I need this to search and allow change to hostname, ipaddress and dlci i have the interface and the 3 buttons created but i have no idea about what code to put in. Ideally it would be nice to click the button and then have a pop up asking for the entry and so on.....
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sirbountyCommented:
How about
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
FileData=objFSO.OpenTextFile("C:\SourceFile.txt").ReadAll
OldHost="something"
OldIP="111.22.33.44"
OldDlci="something"

strHost=InputBox("Enter the new HostName")
strIP=InputBox("Enter the new IP")
strDlci=InputBox("Enter the new dlci")

Set NewFile=objFSO.CreateTextFile("C:\TargetFile.txt")
NewFile.Write Replace(Replace(Replace(FileData,OldHost, strHost), OldIP, strIP), OldDlci, strDlci)
NewFile.Close

Set NewFile=Nothing
Set objFSO=Nothing
0
TCHURCH65Author Commented:
Almost there.....it won't make the change to the new file.  Like the hostname, ip addrress, dlci
0
sirbountyCommented:
How's the file laid out?
I was under the impression that those values were already there?
If you filled in the 'old' variables, it should simply replace them...
Can you post a copy? (mask the data if you need to)
0
TCHURCH65Author Commented:
The file is just a common cisco config file :

for example:
hostname c2600

I really appreciate your help
0
sirbountyCommented:
Haha - common to many people, maybe, but I haven't worked with Cisco config files in years... :^)

Are you updating these lines?
OldHost="c2600" '<<<
OldIP="111.22.33.44" '<<<
OldDlci="something" '<<<
0
TCHURCH65Author Commented:
Yesssss...............

Very sorry....
0
sirbountyCommented:
Does the host get altered with this version?

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
FileData=objFSO.OpenTextFile("C:\SourceFile.txt").ReadAll
OldHost="something"
OldIP="111.22.33.44"
OldDlci="something"

strHost=InputBox("Enter the new HostName")
strIP=InputBox("Enter the new IP")
strDlci=InputBox("Enter the new dlci")

Set NewFile=objFSO.CreateTextFile("C:\TargetFile.txt")
NewFile.Write Replace(FileData,OldHost, strHost)
NewFile.Close

Set NewFile=Nothing
Set objFSO=Nothing
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TCHURCH65Author Commented:
Sorry. I creates the file but no changes made.
0
TCHURCH65Author Commented:
I just tried it again. It worked. My fault. I had to change the name of the varialbe to c2600
You got it!
0
sirbountyCommented:
:^)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.