简体   繁体   中英

alternative to End statement in VBA

I have a Procedure which calls a module. Something like this:

Procedure:

Sub Procedure()

    Module1.SubProcedure()

    If Global.Variable = "A" Then
        ...
    End If

End Sub

Module1:

Sub SubProcedure()

    If x then 
        Exit Sub
    ElseIf y then
        End
    End If

End Sub

Using 'End' resets the Global.Variable. Is there any alternative to 'End' Which would stop the execution of Procedure() and preserve the value of Global.Variable?

You can use a Function instead of using a subprocedure and then return a boolean like this :

Function SubProcedure() as Boolean

    If x then 
        SubProcedure = false
    ElseIf y then
        SubProcedure = true
    End If

End Function

and add these line to the procedure code :

if module1.subprocedure then
   End
end if

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM