Results 1 to 7 of 7

Thread: [2005] Do "x" only at first runtime

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    13

    Resolved [2005] Do "x" only at first runtime

    Hello,

    I'm making a program and I want to x code to be executed only at the first runtime. How could i make this? I have no idea what code it could be, but you could se how I mean with this code:

    HTML Code:
    Private Sub TestIfFirstRun
    If App.FirstRun Then         ' App.x is from vb6 but its just an example
    
             MsgBox("First Run")
    
    Else
    
             GoTo start
    
    End If
    
    start:
    
    MsgBox("Start")
    End Sub
    If anybody knows if it's any API or function for this please reply!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Do "x" only at first runtime

    Go into your project properties (Project menu, the option at the very bottom), then click the Settings tab.
    Here you can create settings for your application. Create a setting of type boolean, set its value to True, and give it a good name...say "FirstExecution".
    Here's the code you'll need now:
    VB.NET Code:
    1. If My.Settings.FirstExecution Then
    2.             'Do whatever you want.
    3.             My.Settings.FirstExecution = False
    4.         End If

    This can be done in many ways, so this is just one of many.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] Do "x" only at first runtime

    Go into the Settings tab of the MyProject page and add a variable there with a scope of User. Call it "FirstRun" or something and make it a Boolean.

    Then in your code:

    Code:
    Private Sub TestIfFirstRun
    If My.Settings.FirstRun = False Then
    
             MsgBox("First Run")
             My.Settings.FirstRun = True
             My.Settings.Save
    
    Else
    
             GoTo start
    
    End If
    
    start:
    
    MsgBox("Start")
    End Sub
    Oi! Atheist beat me to posting a solution again.
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Do "x" only at first runtime

    i don't recall, but if my.settings is saved automagically, then you need to set it to true. of course the boolean could just be dim'ed

    Dim OneTime as Boolean = True


    If OneTime then
    onetime = false
    'one time code here
    end if
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    13

    Re: [2005] Do "x" only at first runtime

    Thank you, it worked!

    OT: When I copy VB code from the VB code box you put, I get all the numbers of the lines like

    1.
    2.
    3.
    4.
    5.


    Can i do anything about this, because if I copy like 70 lines it's very annoying!

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] Do "x" only at first runtime

    You could use our code as a suggestion of what to do and then write it yourself. That would solve the problem.
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Do "x" only at first runtime

    i totally misunderstood. i thought it was code to run once each time the app was run, not just run one time.

    i gotta ask, what are you trying to do just once? i ask because maybe my.settings isn't right, but without knowing the WHAT it is hard to know.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width