Click to See Complete Forum and Search --> : Notepad question
Lieu
Jun 20th, 2000, 11:31 PM
Hello All,
My question is:
Is there a way to open up the file (Notepad), and do the search for a certain word and then change it to some different word ???
Thanks,
you can open up a text file that you would normally open in notepad and do pretty much anything you want to it.
look into :
OpenAsTextStream method /file system object/
instr function
mid function
here is the code to open a text file and read a
line from it.
Sub TextStreamTest()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile "test1.txt" 'Create a file
Set f = fs.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write "Hello World"
ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
s = ts.ReadLine
MsgBox s
ts.Close
End Sub
now just figure out how you want to parse the line and replace the data.
Nitro
Jun 21st, 2000, 05:37 AM
BG!
What is the difference with your method and the regular Open File Output as #1
Lieu
Jun 21st, 2000, 05:48 AM
Hi BG,
The part of parse the line and replace the data is where I dont know what to do.
Example: I have the following data
[inetinfo]
Disable=1
[services]
I'd like to replace
"Disable=1" TO "Disable=0"
Thank you in advance
nitro,
This way uses the file system object(scrrun.dll)
It has a lot of file system methods, like, Returning file attributes, editing txt files, directory and file commands. it's pretty easy to use and saves a lot of time coding.
lieu,
hold on let me find the code for ya
Nitro
Jun 21st, 2000, 06:15 AM
Thanks for the clarification buddy!
Have a nice day!
looks like you should be using a .ini file, check this link out, the code is there already.
http://visualbasic.about.com/compute/visualbasic/library/weekly/aa121998.htm
Lieu
Jun 21st, 2000, 06:48 AM
Thank You very much BG for your information. It works beautifully
Thanks again
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.