Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inside a TextFile (Help)

Status
Not open for further replies.

meny21

IS-IT--Management
Oct 4, 2002
101
MX
Hi Guys!

Does anyone know how can I do this thing using Visual Basic?

I have a TextFile (Example: MyText.TXT), and I need to change a value inside this file.

First I need to find the text that I need to change
(Example: "Key-A")

Then I need to change the value inside the text file
(Example: "Key-B")

Can I do this change using VB?

Thanks for any help Guys

MR

P.D. Also, this file is in a directory with other text files
(Example: other 3 files), Can I with VB check inside every text file and replace a text when I find it in every text file?

 

This is one way to do it

in a sub...

Dim buffer as string

'Opens Text File in application Directory
open app.path & "\myText.txt" for input as #1
buffer = input (LOF(1),1)
buffer = Replace(Buffer,"Key-A","Key-B")
Close #1

'Saves Text File to application Directory
Open app.path & "\myText.txt" for output as #1
print #1, buffer
close #1
 
Good MattStech,

Your are good working with textfiles.......

Also another question about the same

I have many files in that directory, how can I make a Loop that find inside every text file and replace the text that I need to replace with this code?


 
You can put MattSTech's code inside of this loop:

Code:
    Dim curfile As String
    
    curfile = Dir("C:\")
    Do While curfile <> ""
        Debug.Print curfile
        curfile = Dir
    Loop

Also, you may utilize the search feature of this forum to find answers to your questions. This has been discussed many times here. You may want to read faq222-2244 as to why to do a search first.

Good Luck!
 
Thanks so much Guys....

I'm learning very good about working with text files using Visual Basic... With the tips that you gave me helped me too much.

Just one Last Thing I think More difficult:

I have inside a text file something like this:

"This is a test file, how can I do this"

I need to get inside this text...
Find the word "test"
Find the word "can"
and only extract this text part "test file, how can" in a variable

Can I do this with VB?




 
You may also want to look at using regular expressions to do this. Search this forum for RegExp and you'll find many good examples.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top