help on a command that will only run on first start of program

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

    help on a command that will only run on first start of program

    this is my code

    Private Sub Form1_load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

    RichTextBox.Loa dFile("C:\\file notes", RichTextBoxStre amType.RichText )

    End Sub


    Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As

    System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing

    RichTextBox.Sav eFile("C:\\file notes", RichTextBoxStre amType.RichText )

    End Sub


    when i open my app it comes up with an error , because it trying to load a file that is not there , it there a 'runonce' command which will only run on the first ever run of the program ( a command to create the file "C:\\filenotes" ) . This would solve my problem

    ( the code is very basic generally because i'm new to vb)


    thanks for your time / help
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by ooroboo
    when i open my app it comes up with an error , because it trying to load a file that is not there , it there a 'runonce' command which will only run on the first ever run of the program ( a command to create the file "C:\\filenotes" ) . This would solve my problem

    ( the code is very basic generally because i'm new to vb)


    thanks for your time / help
    A lazy solution will be adding

    [CODE=vb]on error resume next[/CODE]

    at the begining of the sub, so if it doesnt find the file, it'll skip that line, and wont stop the app.

    I'd recomend you that also write
    [CODE=vb]on error goto 0[/CODE]
    in some point where you want the code to start showing you the errors again.

    HTH

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      It seems as though the more sensible approach would be to have your application's startup code check whether the file exists and if not, create it. That way, it won't matter whether it has been run before.

      Comment

      Working...