Results 1 to 4 of 4

Thread: Explicit Function return (RESOLVED)

  1. #1

    Thread Starter
    Hyperactive Member divined's Avatar
    Join Date
    Aug 2004
    Location
    Thessaloniki, Greece
    Posts
    447

    Resolved Explicit Function return (RESOLVED)

    Hello everybody

    I have this very simple question. Suppose the following function :

    Code:
    Function ABC As Boolean
    Do While <condition>
         
         If <condition> Then
           
            <statements> 
            On Error GoTo ErrorHandler
    
            <other_statements>
            ABC = True  ' Correct master password
            Return                      ' Return
         End If
         
         GoTo ShuntErrorHandler
         
    ErrorHandler:
         MsgBox "ERROR!ï", vbCritical
         If Err.Number Then
           Resume ShuntErrorHandler
         End If
    ShuntBadErrorHandler:
         
       Loop
    End Function
    In this code, I just want the function to return a value and give control back to the calling procedure-function. But this does not occur! How do I tell the function to exit. Does the assignment of the function value need to be the last statement of the function?

    thx, in advance

    George Papadopoulos
    Last edited by divined; May 4th, 2005 at 01:28 AM.
    SteadFast!

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Explicit Function return

    VB Code:
    1. Exit Function
    That should do it.

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Explicit Function return

    Something like this:


    Function ABC As Boolean
    Do While <condition>
    ABC = False
    On Error GoTo ErrorHandler
    If <condition> Then
    <statements>
    <other_statements>
    ABC = True ' Correct master password
    Exit Function ' Return
    End If
    Loop
    exit function
    ErrorHandler:
    MsgBox "ERROR!ï", vbCritical
    If Err.Number Then
    Resume ShuntErrorHandler
    End If
    End Function

    the forums acting up


    VB Code:
    1. Function ABC As Boolean
    2. Do While <condition>    
    3.      ABC = False
    4.      On Error GoTo ErrorHandler
    5.        If <condition> Then      
    6.         <statements>
    7.         <other_statements>
    8.         ABC = True  ' Correct master password
    9.         Exit Function                     ' Return
    10.      End If
    11.      Loop  
    12.      exit function  
    13. ErrorHandler:
    14.      MsgBox "ERROR!ï", vbCritical
    15.      If Err.Number Then
    16.        Resume ShuntErrorHandler
    17.      End If    
    18. End Function

  4. #4

    Thread Starter
    Hyperactive Member divined's Avatar
    Join Date
    Aug 2004
    Location
    Thessaloniki, Greece
    Posts
    447

    Re: Explicit Function return

    ok. that was it. I just wasn`t aware of the statement. I was more on the grounds of the Return statement in C.

    thx, for the help!
    SteadFast!

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