need help visual basic 9

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ooroboo
    New Member
    • Feb 2008
    • 20

    need help visual basic 9

    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(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

    RichTextBox1.Lo adFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)
    On Error Resume Next
    RichTextBox1.Sa veFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)

    End Sub

    Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing

    RichTextBox1.Sa veFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)

    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
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by ooroboo
    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.
    [CODE=VB]
    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

    RichTextBox1.Lo adFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)
    On Error Resume Next
    RichTextBox1.Sa veFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)

    End Sub

    Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing

    RichTextBox1.Sa veFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)
    [/CODE]
    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:



    Please write if you need more help!

    Dököll

    Comment

    • ooroboo
      New Member
      • Feb 2008
      • 20

      #3
      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

      Comment

      • Sick0Fant
        New Member
        • Feb 2008
        • 121

        #4
        Originally posted by ooroboo
        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(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

        RichTextBox1.Lo adFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)
        On Error Resume Next
        RichTextBox1.Sa veFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)

        End Sub

        Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing

        RichTextBox1.Sa veFile("C:\Outp utFolder\lol", RichTextBoxStre amType.PlainTex t)

        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.

        Comment

        • Sick0Fant
          New Member
          • Feb 2008
          • 121

          #5
          Originally posted by ooroboo
          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?)

          Comment

          Working...