CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: initialize static variables in a sub

  1. #16
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Ungi,

    No, you don't need that first call last call scheme. Because the static variable can be initialized by just passing a value in the sub routine. And the initialization may be done on the sub main or main form load event..

    Initialize the static variable to true:
    Private Sub Form_Load()

    MyProcedure True

    End Sub

    The timer event would be just calling the sub routine wihtout argument:
    Private Sub Timer1_Timer()

    MyProcecedure

    End Sub
    And finally, the sub routine :
    Public Sub MyProcecedure(Option ByVal st_initVal As Variant)
    Static WaitOnce As Boolean

    'check initializing
    If Not IsMissing(st_initVal) Then
    WaitOnce = st_initVal
    Exit Sub
    End If


    'check if to wait once
    If WaitOnce Then
    WaitOnce = False
    Else
    '--- do something

    'check if to wait once
    waitonce = iif (somecriteria, true, false)
    end if

    End Sub
    Busy

  2. #17
    Join Date
    Apr 2002
    Posts
    388

    Talking

    Thank you!!

    That's really a good alternation. If I'm not on the wrong way in this case it is either possible to "reset" the function! That's good!
    mfg Ungi

    Music, music and VB. VB is like music: You never know how it is interpreted.

Page 2 of 2 FirstFirst 12

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)