CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2004
    Location
    Coimbatore
    Posts
    25

    Question Procedure Executes after Unload Me Statement

    Private Sub Command1_Click()

    MsgBox "WelCome"
    Unload Me
    TestFun

    End Sub
    Private Sub TestFun()

    MsgBox "Why does this Execute?"

    End Sub

    Why the Procedure TestFun Execute After the Unload Me Statement.
    I dont want to execute any procedures or Statements after unload Me Statement. Pls give a Solution to this problem.

    Thx in Advance.

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Procedure Executes after Unload Me Statement

    Unload Me
    Exit Sub
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  3. #3
    Join Date
    Jun 2004
    Location
    Coimbatore
    Posts
    25

    Question Re: Procedure Executes after Unload Me Statement

    Thx,

    My Case is

    Private Sub Command1_Click()
    MsgBox "WelCome"
    TestFun
    MsgBox "Why does this Execute?"
    End Sub

    Private Sub TestFun()
    MsgBox "TestFun Called"
    Unload Me
    Exit Sub
    End Sub

    Pls. Help me. I need not want to execute any of the Statements after the Unload me statement.

    Thx in Advance.

  4. #4
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Procedure Executes after Unload Me Statement

    Code:
    Private Sub Command1_Click()
        MsgBox "WelCome"
        TestFun
        MsgBox "Why does this Execute?"
    End Sub
    
    Private Sub TestFun()
        MsgBox "TestFun Called"
        Unload Me
        End
    End Sub
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  5. #5
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: Procedure Executes after Unload Me Statement

    Code:
    Private Sub Command1_Click()  
    MsgBox "WelCome"  
    TestFun  'u call tesfun procedure..after that it will popup msbox below..that's why
    MsgBox "Why does this Execute?"  
    End Sub    
    
    Private Sub TestFun()  
    MsgBox "TestFun Called"  
    Unload Me  
    Exit Sub  ' not really need this..
    End Sub
    if u don't want to be excuted then try remove the red line..if u still wish that line that add End statement at form_unload though it's not recomended..

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  6. #6
    Join Date
    Jun 2004
    Location
    Coimbatore
    Posts
    25

    Re: Procedure Executes after Unload Me Statement

    Thanks
    But in my case

    I have Written a Procedure To insert Entries into Different Tables
    Within One Procedure named
    Private Sub SaveEntries()
    on error goto err
    SaveHeader 'Procedure to insert header table
    SaveDetail 'Procedure to insert into detail table
    msgbox"Entry Saved"
    err:
    ' Rollbacktrans
    end sub

    Private sub SaveHeader()
    on error goto err
    'insert statement and other codes
    err:
    unload me
    end sub

    If Any Error Occurs in any of the Procedure saveheader or in detail then other statement or other procedure should not be executed and Form should be closed and Mdiform form should be there and not to close the whole project

    pls help me

  7. #7
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Re: Procedure Executes after Unload Me Statement

    in that case..maybe u should use function instead of sub

    something like this
    Code:
    private function InsertToTable As boolean
      a= true  
    on error goto errHandle
      'ur code here
      exit sub 'u forgot to add this before ur errHandle
    errHandle:
      a = false
    end function
    and to use it
    Code:
    if InsertToTable=true then 'process other
    hope u get the idea..

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  8. #8
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Procedure Executes after Unload Me Statement

    Code:
    Private Sub SaveEntries()
        On Error GoTo err
        If SaveHeader Then 'Procedure to insert header table
            SaveDetail 'Procedure to insert into detail table
            MsgBox "Entry Saved"
        Else
            MsgBox "SaveHeader() Failed"
            err.Raise 999, "SaveHeader()", "SaveHeader failed"
        End If
        
        Exit Sub
    err:
        ' Rollbacktrans
    End Sub
    
    ' Returns true if successful
    Private Function SaveHeader() As Boolean
        On Error GoTo err
        'insert statement and other codes
        
        ' Function successful, set to true and exit
        SaveHeader = True
        Exit Function
    err:
        ' Function failed, set to false and exit
        SaveHeader = False
    End Function
    Ya beat me to it erickwidya, but might as well post this anyway
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  9. #9
    Join Date
    Jun 2004
    Location
    Coimbatore
    Posts
    25

    Re: Procedure Executes after Unload Me Statement

    Thx Guys for Immediate Response.

    I will Check it out and Reply.

  10. #10
    Join Date
    Oct 2004
    Location
    Adelaide, South Australia
    Posts
    125

    Re: Procedure Executes after Unload Me Statement

    Well, it looks to me like the initial question was a theoretical one, which received a number of practical reponses.
    The theoretical answer is:
    Private Sub Command1_Click() was popped onto the stack.
    Stack = Private Sub Command1_Click()

    MsgBox is then executed.
    Stack = (from top) Private Sub Command1_Click() , MsgBox.
    OK or cancel on MsgBox pops it from stack.
    Stack is now = Private Sub Command1_Click()

    Unload Me executes
    Stack is now = Private Sub Command1_Click() , Unload Me
    Unload Me finishes executing
    Stack is now = Private Sub Command1_Click()

    TestFun executes
    Stack is now = Private Sub Command1_Click() , TestFun
    TestFun finishes executing
    Stack is now = Private Sub Command1_Click()

    Private Sub Command1_Click() finishes executing
    Stack is now empty.

    D
    'shut up and play yer guitar' - Frank Zappa

  11. #11
    Join Date
    Jul 2004
    Location
    Jakarta, Indonesia
    Posts
    596

    Talking Re: Procedure Executes after Unload Me Statement

    Ya beat me to it erickwidya, but might as well post this anyway

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL

  12. #12
    Join Date
    Jun 2004
    Location
    Coimbatore
    Posts
    25

    Question Re: Procedure Executes after Unload Me Statement

    Hi,

    Changing the Procedures to Functions is good Solution. But I have more than 100 forms in my project, so i need to change these in all those forms which is tedious and time consuming. Is there any other solution other than this (something like using some API) and unloading form and after unloading it should wait in the MDI Form. The application should not Close.

    Help me.

    Thx in Advance.

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