Closing a file and the form

  • Thread starter Thread starter Kelly
  • Start date Start date
Ok, I took out the shell command and the file closes now. Yay! I had no idea
that was the problem. Thank you. I added the line:
formName.activeform.hide() to my code and it seems to be working great now.

Thanks for all of your help! :)

-Kelly

Kelly said:
LOL...well, I was told I had to launch Notepad.exe to get the txt file to
open. So, I looked up the Shell command and implemented it into my code.
Since the file opened up, I assumed I was doing it correctly.

Is that part not needed?

-Kelly

and
comes
 
Thank you - you've been a great help! :)

-Kelly

Herfried K. Wagner said:
Kelly,

:)

You didn't.


The meaning of the term "open" in relation to files is overloaded:

(1) Opening a file means that you start an application that is able to
read/process/display/edit the file. In this case, the /user/ opens
the file, for example, by doubleclicking it in Explorer. This can
be done in VB using the 'Shell' command too. This command will
launch an application with a certain file.

(2) Opening a file from the developer point of view means to perform
steps that are necessary to access the data stored in a file and/or
make it ready for reading data from the file and/or writing data to
the file. In VB.NET, this can be done using 'FileOpen', etc., or
the 'System.IO.StreamWriter'/'System.IO.StreamReader' class.

I assume that you want to do (1).


There is everything OK with that. Glad to see that people are using
VB.NET.


Text files can be simply written using 'FileOpen', etc., or the
'Stream*' classes. For Excel files and other binary formats, it's not
as easy because often the formats are not documented. In these cases,
Office automation can be used to write the data to the file.


For simple text files, skip the 'Shell(...)' line.
 
Kelly,
Is that part not needed?

No, as I said already as answer on your question yesterday. And asked you
today again why you did it.

Read the file using the streamreader into the textbox.
You can do that in one time with (copied partially from MSDN and than
changed, so there can be a lot of typos and it is just a kind of pseudo
sample)

Imports System
Imports System.IO
Imports System.Text

Private Sub FormLoad
Dim path As String = "c:\temp\MyTest.txt"
Try
Dim sr As StreamReader = New StreamReader(path)
'This allows you to do one Read operation.
myTextbox.text = sr.ReadToEnd())
sr.Close()
Catch e As Exception
Messagebox.show(e.tostring)
End Try
end sub
Private sub Abutton clicked
Try
File.Delete(path)
'Above is normally not the right way better is to save it with
'a tempory name and when it is ok to change the name (file.move)
Dim sw As StreamWriter = New StreamWriter(path)
sw.Write(Textbox.Text)
sw.Close()
Catch e As Exception
Messagebox.show(e.tostring)
End Try
End Sub
End Class
////

I hope this helps?

Cor
 
Ok, sorry. I didn't catch the part about taking the shell command out
yesterday. I was told by someone else I needed it and so never really
questioned that part of the code. I see the difference now though. I'm
learnin... :)

-Kelly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top