"Lumpierbritches" <lu*************@aol.com> wrote in message
news:20***************************@mb-m21.aol.com...
How do you consider this is a solution. I have no idea what you're
talking about. I just wanted to know, in code, how to open a text file and append
text from a field on a form, using the clipboard paste, from a command
button>?>>>>>????
Michael
It is the colution you asked for. You asked how to open a notepad/wordpad
file, then vaguel amended it to open a text file. I believe what you are
looking foris reading/writing to a text file. You are correct in using a
StreamReader/StreamWriter, but, if it's not defined, look at where you
defined it in code. You must always be aware of the scope of your object
declerations. Consider the following:
Private Sub Main
Dim SR As StreamReader
End Sub
Private Sub WriteFile(ByVal Input As String)
SR = New StreamReader("C:\somefile.txt")
MyText = SR.ReadToEnd
SR.Close
End Sub
You will get your Undefined Error because WriteFile sub has no clue what
SR is because it's declared in Main sub. This has never changed in any
language I know of, but, under VB6, it would have been made a varient unless
you had Option Explicit on, which is default under .NET, then you'd get an
Unefined Error. The two solutions are to either define SR as a FormLevel
object, by this I mean outside of any procedure, or as a Procedure level
object. Now, something to consider, FormLevel objects always exist in
memory as long as the form does, so, if you only need it once or twice, make
it procedure level and the GarbageCollector will gett ride of it when you
don't need it and thus free up resources for other objects. NOTE: my
discription of the Garbage Collector is not entirely accurate, but the gist
is correct.
So, IMHO, try tthis code:
Private Sub WriteFile(ByVal Input As String)
Dim MyText as String
Dim SR As StreamReader = New StreamReader("C:\somefile.txt")
MyText = SR.ReadToEnd
SR.Close
Dim SW As StreamWriter = New StreamWriter("C:\somefile.txt")
SW.Write( MyText & Input)
SW.Close
End Sub
This will read in the textfile, and write it right back out. Now, another
nifty trick of the StreamWriter, open it and Append to the file, eliminating
the StreamReader all together. Check into it. They are both in the
System.IO namespace.
HTH
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004