i have sub1 that call sub2.
if certain condition is meet, i would like to exit sub2 and at the same time exit sub1 (the one which is calling sub 2) in sub2
how do i do that?
thank you.
Printable View
i have sub1 that call sub2.
if certain condition is meet, i would like to exit sub2 and at the same time exit sub1 (the one which is calling sub 2) in sub2
how do i do that?
thank you.
Make it a function returning True or False:
VB Code:
Private Sub Sub1 () Dim blnExit as boolean 'bla bla_2 blnExit = Func2(bla) if blnExit then exit sub endif end sub Private function Func2(strBLA as string) as boolean if len(strBLA) < 4 then func2 = true endif 'bla bla 'text1.text = ucase(strbla) func2 = False end function
hmmm...thanks!!!!
Add [RESOLVED] to the topictitle pleazzz
is there any other better solution to this problem.....i have lots of 'if then ' in sub2 that is being called? :)
Raise an error. That will get you out of both subs :D
Woka
how do i raise an error?
VB Code:
err.raise 666
Then check in the errorhandler if the errornumber = 666 then you know it is the errer you raised...
WokaVB Code:
Private Sub MySub1() On Error Goto ErrHandler Call MySub2 Exit Sub ErrHandler: If Err.Number <> vbObjectError Then Err.Raise Err.Number, Err.Source, Err.Description End if End Sub Private Sub MySub2() On Error Goto ErrHandler If "Fish" = "Woof" Then Err.Raise vbObjectError 'forces code to jump to errhandler End If Exit Sub ErrHandler: Err.Raise Err.Number, Err.Source, Err.Description End Sub