How to run a function only once?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: How to run a function only once?

  1. #1
    Fortron Guest

    How to run a function only once?

    For my application i want to run a function only once at program start.
    Whenever the use starts the program again, i don't want that function to run
    again.

    How to i make that work?



  2. #2
    Craig Brown Guest

    Re: How to run a function only once?


    Fortron,

    How about putting a registry entry out there and then checking for it?

    The first thing you do is to run the GetSettings. If yours exists, then
    don't do anything, otherwise save whatever it is you want to save or do and
    also run the SaveSettings to ensure that you don't come through again...

    Craig Brown


    "Fortron" <fortron@f2s.com> wrote:
    >For my application i want to run a function only once at program start.
    >Whenever the use starts the program again, i don't want that function to

    run
    >again.
    >
    >How to i make that work?
    >
    >



  3. #3
    Mark Alexander Bertenshaw Guest

    Re: How to run a function only once?


    "Fortron" <fortron@f2s.com> wrote:
    >For my application i want to run a function only once at program start.
    >Whenever the use starts the program again, i don't want that function to

    run
    >again.
    >
    >How to i make that work?
    >


    "Fortron" -

    What you ask is impossible. However, you can ensure that the main body of
    code in a function is not executed by a simple Static flag, e.g.

    Function Init()
    Static bCalled As Boolean

    If Not bCalled Then
    ' ... your code ...
    bCalled = True
    End If

    End Function


    HTH

    --

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    Chordiant Software, Inc.
    Brentford
    UK

  4. #4
    jim Guest

    Re: How to run a function only once?


    Or you can put a flag in the registry that shows the function has been run.


    "Mark Alexander Bertenshaw" <mark.bertenshaw@virgin.net> wrote:
    >
    >"Fortron" <fortron@f2s.com> wrote:
    >>For my application i want to run a function only once at program start.
    >>Whenever the use starts the program again, i don't want that function to

    >run
    >>again.
    >>
    >>How to i make that work?
    >>

    >
    >"Fortron" -
    >
    >What you ask is impossible. However, you can ensure that the main body of
    >code in a function is not executed by a simple Static flag, e.g.
    >
    >Function Init()
    >Static bCalled As Boolean
    >
    > If Not bCalled Then
    > ' ... your code ...
    > bCalled = True
    > End If
    >
    >End Function
    >
    >
    >HTH
    >
    >--
    >
    >--
    >Mark Alexander Bertenshaw
    >Programmer/Analyst
    >Chordiant Software, Inc.
    >Brentford
    >UK



  5. #5
    Alexandre Locas Guest

    Re: How to run a function only once?


    Write a flag in a file, database or registry to indicate your app that the
    function as already run.

    "Fortron" <fortron@f2s.com> wrote:
    >For my application i want to run a function only once at program start.
    >Whenever the use starts the program again, i don't want that function to

    run
    >again.
    >
    >How to i make that work?
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center