473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Open wordpad/notepad file

Thank you in advance for any and all assistance. It is greatly appreciated.

I would like a command button in VB.Net 2002 to open a text file, then to allow
text from a textbox on the current form to be appended to that text file. Is
there a place where I can see code to do this?

I have the data/text on the clipboard using the clipboard class, now I want to
append it to the text file either in Notepad or Wordpad. I have tried using the
StreamWriter and get that it's undefined under the Private_Sub Function of the
command button. What am I doing wrong?

Michael
Nov 20 '05 #1
7 13142
* lu*************@aol.com (Lumpierbritches) scripsit:
I would like a command button in VB.Net 2002 to open a text file, then to allow
text from a textbox on the current form to be appended to that text file. Is
there a place where I can see code to do this?
\\\
Dim p As Process = Process.Start("notepad")
Try
AppActivate(p.Id)
Catch
End Try
Clipboard.SetDataObject("Hallo Welt") ' Text in Clipboard setzen.
SendKeys.Send("^v") ' Strg+V auslösen.
///
I have the data/text on the clipboard using the clipboard class, now I want to
append it to the text file either in Notepad or Wordpad. I have tried using the
StreamWriter and get that it's undefined under the Private_Sub Function of the
command button. What am I doing wrong?


You will have to import the 'System.IO' namespace ('Imports System.IO'
on top of the file). Notice that this won't make any sense if you want
to append the text using Notepad or Wordpad.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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
Nov 20 '05 #3

"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
Nov 20 '05 #4
Mr Lumpier Britches,

Mr Wagner gave you an accuracte answer for your questions. The code he
posted will paste the current clipboard content into the notepad.

What more do you want ?
OHM

Lumpierbritches wrote:
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


--
Best Regards - OHM
one.handed.man{at}BTInternet{dot}com
Nov 20 '05 #5
* lu*************@aol.com (Lumpierbritches) scripsit:
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>?>>>>>????


Mhm... That's exactly what the code I posted is doing. It starts
Notepad and pastes some text into it using the clipboard.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Thank you everyone. In VB 6, you could just use Shell and open a word / notepad
file and then using Keystrokes go to the end of the file and paste the
clipboard.

I'm just trying to take a command button and have code open a word/notepad file
and append some text in a form textbox, that's on the clipboard to a text file.

I'm not a fulltime coder, just playing with it for some personal use. When I
put any code in the button click event, I get undefined on Streamwriter or
reader. I'm going to try new things, but I was looking for a simple:
shell:(c:\program file\myfile.txt)
^{end}
^V
or something similar.

But, again, thank you for all your help. I'm just frustrated with .Net. It's
not anything like VB6, which took me awhile to get coding down in it.

Michael
Nov 20 '05 #7
* lu*************@aol.com (Lumpierbritches) scripsit:
reader. I'm going to try new things, but I was looking for a simple:
shell:(c:\program file\myfile.txt)


Use 'System.Diagnostics.Process.Start(<filename>)' instead.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
7
by: Hareth | last post by:
When VS2003 is installed : I can open Form1.cs w/ windows "open with" contextmenu, then it opens the file w/ notepad & it works fine but after installing VS2005, "open with" doesnt...
3
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open...
4
by: Lorimer | last post by:
Thanks in advance for any help received. Is it possible to automatically display a text file in Wordpad using VB.NET and if so how do I do it? Thanks again L
9
by: Dino Buljubasic | last post by:
If I want to delete a file I can call File.Delete(filePath) but what happens if I am trying to delete the file that is open??? In java you would do someting like int status =...
2
by: GW | last post by:
After the conversion and fixing some errs VS2005 threw, project ran OK. Opened xxx.vbproj file after the conversion to VS2005 from VS2003. Changed (usng wordpad) ../msbuild/2003 to 2005...
6
by: Moumen VB.NET 2003/2005 Developer | last post by:
How can I detect if a file sitting on a network drive is still open by another application? This application resides on another machine on the network? I am using VB.NET 2003 Your help is...
11
blyxx86
by: blyxx86 | last post by:
Alright, I'm trying to create a form that would allow certain documents to be opened by selecting an option within a combo box and then having a single button to open the pertaining file. I know...
6
by: =?Utf-8?B?TUNI?= | last post by:
I try to open a log file that is logging infomation by another process: StreamReader sr = File.OpenText(filePath); I got the exception message: The process cannot access the file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.