Skip to content

How to exit current method outside the own method

amin choroomi

Asked Sep 1, 2005, 11:02 AM EDT4 answers
Share
LinkedInX

hi

i want to exit sub / function outside the own method like this

public sub method1()
     'the procedure code
     call method2(1)
     'the remind procedure code
end sub

public sub method2(number as integer)
     if number=1
           'exit method1()
     end if
end sub

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    public sub method1()
         'the procedure code
         if method2(numberToPassIn) then exit sub
         'the remind procedure code
    end sub

    public function method2(number as integer) as boolean
         return number = 1
    end function

    This code assumes that you are doing nothing else in method2 other than checking if the number passed in is equal to 1.
    0
  • 0
    thanx for your reply

    but i dont wanna do that because ican not

    i actualy dont call method2()
    but i only used an example to tell what i mean;

    could you help me exiting method1() @ method2() ?
    0
  • 0

    Well, unless you are using threading you will not be in Method1 and Method2 at the same time.

    I guess I don't really understand your question.  Either Method1 is running or Method2 is running.  If Method1 did not call Method2 then you can't "exit" Method1 from Method2.

    Now, if you want to limit the excution of Method1 based on something in Method2 you could do something like this:

    Private RunMethod1 as boolean = true

    Private Sub Method1()
       If Not RunMethod1 Then Exit Sub
       'do stuff
    end sub

    Private Sub Method2()
       'if you don't want to run method1
       RunMethod1 = false
    End Sub

    0
  • 0
    hi Andrew

    let me explain my project

    i have already 100 or more functions like method1()

    also i have already a public property called MyPro1

    in the Set(value as object) ....  End Set
    part of this property i have written mycode like method 2


    i change MyPro1 in all of 100 functions

    then i want to exit each one of methods that changed the property in special condition.

    if u dont got it tell me to send the real class as a eMail to you.

    thanx more for attention.
    0