CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 1999
    Posts
    6

    What determines the value of App.PrevInstance?

    I've got this code in my program

    If App.PrevInstance then
    MsgBox "A previous instance running"
    End
    End If




    If I run the exe, exit the program, then restart the program I get the prev instance message. This is happening even when I am the only one running the program. So, I figure something must be left open when I exit the program. How can I found out what is causing App.Prev.Instance to be true?

    Thanks for the help!!


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: What determines the value of App.PrevInstance?

    in NT use the Task-Manager (Ctrl+Alt+Del - Task-Manager) to check whether your program is still running after you try to end it.
    make sure that you unload all your forms when you try to end your program.
    When all else fails, use the End statement to end your program.


  3. #3
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    58

    Re: What determines the value of App.PrevInstance?

    Hi,
    I agree with Lothar; you must be sure that no form still hangs around in memory.
    Closing elegantly your application and to be informed what's going on you can do a.o. the following:

    Put code in the FormQueryUnload , I anticipate you have also a MDI Form. so:
    ////////////////////////////////////////
    Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    'Code taken from Inside VB, 9705 issue
    Dim intAns As Integer
    Dim strMode As String
    Select Case UnloadMode
    Case 0
    strMode = "Close from control menu"
    Case 1
    strMode = "Unload Keyword"
    Case 2
    strMode = "Windows session is ending"
    Case 3
    strMode = "TaskManager"
    Case 4
    strMode = "MDI Parent is closing"
    End Select
    intAns = MsgBox("Exit the programme?", 1 + 32, strMode)
    If intAns = 1 Then
    'CleanUpJobs

    Unload Me
    Else
    Cancel = 1
    End If
    End Sub

    ////////////////////7
    You can also force ALL child forms to be unloaded, this can be done in this phase of unloading

    Private Sub MDI_FormUnload(Cancel as Integer)

    Dim i as Long
    For i = Forms.Count - 1 To 1 Step -1
    Unload Forms(i)
    Next i




  4. #4
    Join Date
    Jul 1999
    Posts
    6

    Re: What determines the value of App.PrevInstance?

    Thanks Lothar.

    I've unloaded all my forms and used the END statement.

    Part of the problem is that I only get the error if I proceed far enough into the program. i.e. If I exit after a few screens, I get no error.

    (I'm using VB 5 and MS Access.)


  5. #5
    Join Date
    Jul 1999
    Posts
    6

    Re: What determines the value of App.PrevInstance?

    Thanks Jan.

    I'll try that.

    Part of the problem is that I only get the error if I proceed far enough into the program. i.e. If I exit after a few screens, I get no error.
    (I'm using VB 5 and MS Access.)

    I'm also using an FXVideo Control along with some standard VB controls. Is there any way of checking that one of my controls is not closing/unloading properly?

    Thanks again.


  6. #6
    Join Date
    Jul 1999
    Posts
    6

    Re: What determines the value of App.PrevInstance?

    I don’t know if you have time to help me with this, but - here goes:

    My program runs form VB5 with an Access database. Each screen is part of a specific node. The previous instance error only happens when:

    1. I reached the last screen of a node
    2. try to continue when there is not another screen after the current one (this triggers a beep sound)
    3. exit program
    4. restart program


    ‘Code to continue on to next screen

    Case "GOTONEXT"
    TipTimer.Enabled = False
    FXVideo.Command = FX_CLOSE

    If SetNext Then ‘I think this is where my problem is starting
    Call ClearScrn
    Call SetupScreen
    Call StoreJumps
    Else ’trigger sound
    i= mciSendString("CLOSE SAMPLE", 0&, 0, 0)
    i = mciSendString("OPEN " & GetWaveName(GetCommonText("Sound", "NoScreen")) & " ALIAS SAMPLE", 0&, 0, 0)
    i = mciSendString("PLAY SAMPLE", 0&, 0, 0)
    End If



    Private Function SetNext() As Boolean

    On Error GoTo SetNextErr

    If Not RSNodeInfo.EOF Then
    RSNodeInfo.MoveNext
    Else
    SetNext = False
    Exit Function
    End If

    If RSNodeInfo.EOF Then
    RSNodeInfo.MoveLast
    SetNext = False
    Exit Function
    End If

    SetNext = True
    Exit Function

    SetNextErr:
    Select Case ErrorHandler
    Case 3 ' Abort
    End
    Case 4 ' Retry
    Resume
    Case 5
    Resume Next
    End Select

    End Function


    Any ideas? I’m completely stumped.



  7. #7
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: What determines the value of App.PrevInstance?

    You say, that the err comes only if you do deep down in the program flow. So obviously your clean up procedure is not "clean".

    Also you are not showing the sectoin that calls the SetNext fn

    if SetNext then
    .... You are calling 3 fns here
    else
    .. indicating the end to MCI player
    end if
    ??? what are you doing here after this??



    Are you undoing whatever is happening in those
    "ClearScrn" , "SetupScreen" functions?

    If you are using "End" command, just put this
    small like before this and look at the debug print

    Debug.print Forms.Count



    It better print 1 otherwise use the code Jay said ahead in the thread

    Ravi


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

Featured