By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

need help visual basic 9

P: 20
i wont a text file to load into a rich text on box on load , then save when the form closes. my problem has been creating the text file , i am very new for visual basic and could use some help this is my attempt on this.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

RichTextBox1.LoadFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)
On Error Resume Next
RichTextBox1.SaveFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)

End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

RichTextBox1.SaveFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)

when the form is opened for the first time the file has not been created , i thought the the on error resume next would skip it to the next line so the file is created , but not overwritten every time the program is opened .


as i said i am very new to visual basic so please correct or even tell me what i tired to do was rubbish but please help would be very welcome

thanks for your time/help
Rob
May 16 '08 #1
Share this Question
Share on Google+
4 Replies


Dököll
Expert 100+
P: 2,364
i wont a text file to load into a rich text on box on load , then save when the form closes. my problem has been creating the text file , i am very new for visual basic and could use some help this is my attempt on this.
Expand|Select|Wrap|Line Numbers
  1.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         RichTextBox1.LoadFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)
  4.         On Error Resume Next
  5.         RichTextBox1.SaveFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)
  6.  
  7.     End Sub 
  8.  
  9. Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  10.  
  11.         RichTextBox1.SaveFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)
  12.  
when the form is opened for the first time the file has not been created , i thought the the on error resume next would skip it to the next line so the file is created , but not overwritten every time the program is opened .


as i said i am very new to visual basic so please correct or even tell me what i tired to do was rubbish but please help would be very welcome

thanks for your time/help
Rob
Hey buddy!

I don;t know how much help I can be to you, but I added some code tags for you, for visibility.

I use VB 6 a lot; opening a file using Open method seems to be the way to go everytime, here is code regarding text files in VB 6, perhaps you can get an idea there:

http://visualbasic.ittoolbox.com/gro...ng-vb-1419230#

Please write if you need more help!

Dököll
May 17 '08 #2

P: 20
thanks i think this helped to understand it more , but if possible i would still like for help . i am using vista and its seems to decline access when the programs tries to save the file and comes up a error message . any ideas on this and the first problem?

thanks again for the time/help

rob
May 17 '08 #3

100+
P: 121
i wont a text file to load into a rich text on box on load , then save when the form closes. my problem has been creating the text file , i am very new for visual basic and could use some help this is my attempt on this.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

RichTextBox1.LoadFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)
On Error Resume Next
RichTextBox1.SaveFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)

End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

RichTextBox1.SaveFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText)

when the form is opened for the first time the file has not been created , i thought the the on error resume next would skip it to the next line so the file is created , but not overwritten every time the program is opened .


as i said i am very new to visual basic so please correct or even tell me what i tired to do was rubbish but please help would be very welcome

thanks for your time/help
Rob
One thing I would suggest is to use a Try/Catch block instead of On Error GoTo. Try loading the file. Handle the exception in the catch by Creating the file. Only save the file when you're done with it. Come back if you still have a problem.
May 19 '08 #4

100+
P: 121
thanks i think this helped to understand it more , but if possible i would still like for help . i am using vista and its seems to decline access when the programs tries to save the file and comes up a error message . any ideas on this and the first problem?

thanks again for the time/help

rob
Is the file you're trying to save being used by some other program (e.g., is it opened in Notepad?)
May 19 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.