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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I edit a file in Wordpad? 1

Status
Not open for further replies.

aweiss

Programmer
Dec 9, 1999
15
0
0
DE
Hello,

I want to edit a TXT file in Wordpad from VB.
Is this possible?

I hope anyone can help me.

Bye

Alex [sig][/sig]
 
What-ho,

use the Shell() function;

rc = shell("C:\Program Files\Windows NT\Accessories\wordpad c:\file.txt",vbMaximizedFocus)

Make sure you enter the right path for wordpad.exe, this is just where it is on my machine.

Cheerio,

Paul
[sig][/sig]
 
aweiss,

Why? (do want to edit using wordpad)?

Just curious! [sig]<p>MichaelRed<br><a href=mailto:mred@duvallgroup.com>mred@duvallgroup.com</a><br>There is never time to do it right but there is always time to do it over[/sig]
 
Hello,

I must autmatic edit a text file. The User is not allowed to see this. I can't open a file in VB, because the files are to great (>64 kb!). Or can anyone tell me how I edit the only the first row in a file and save it back?

Thanks

aweiss [sig][/sig]
 
Well, how I do it is by using Text Streams. The only problem with them is that it is that you need to read the file into a variable by using FileSystemObjects. If you have a large file, I would recommend using a few variables. To start, access your references from the Project menu and look for &quot;MS Scripting Runtime&quot;. The generic code goes a little something like this:

To Read the first line into memory:

Option Base 1
Dim mFSO as New FileSystemObject, mFile as File
Dim mTS as TextStream, arData(# of lines in file) as string

Private Sub Form_Load()
Dim s as String, i as Integer
Set mFile = mFSO.GetFile([path & filename])
Set mTS = mFile.OpenAsTextStream(For Reading)
s= mTS.ReadLine
for i = lbound(arData) to ubound(arData)
arData(i) = s
s = mTS.ReadLine
Next i
TS.Close
End Sub

Now you have the file in arData to do with what you want.
To edit the first line just modify the contains of arData(1) and life is good. Make sure you dont forget Option Base 1 in the declarations. [sig]<p>Halo<br><a href=mailto:Halo333@juno.com>Halo333@juno.com</a><br>[/sig]
 
Is the file delimited by linefeeds or carrage returns??? How did you create the file? Look to see if the file has line feeds at the ends then all you have to do is write a routine to reat the file line by line writing it out to a new file like this:

Warning: Untested code comming from my head:::

MyFile_in = FreeFile
Open &quot;filename&quot; for Input as MyFile_in
MyFile_out = FreeFile
Open &quot;filename&quot; for Output as MyFile_out

Do While Not EOF(MyFile_in)
Line Input #MyFile_in, Stuff
'Do somthing with the first line like If this is the first line...
'ya-de ya-de ya-de

'Write it out
Print #MyFile_out, Stuff
Loop

Close MyFile_in
Close MyFile_out


Hope this helps ;0)
[sig][/sig]
 
BigFoot,

At least don't open the same filename for In and out -

V E R Y c O n F U s I n G

[sig]<p>MichaelRed<br><a href=mailto:mred@duvallgroup.com>mred@duvallgroup.com</a><br>There is never time to do it right but there is always time to do it over[/sig]
 
You were to insert your filenames in the &quot;filename&quot; space. I did'nt know how to make that clear.
It's a simple text input and output.

Programming 101 class :~P
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top