2013-02-12 16 views
10

ile ilgili daha fazla yürütme makro sonlandırılması, i makro sona gerekir.I usul-A içerisinde bir koşulu ile birden çok yöntem adlı bir <code>method-A()</code>,</p> <p>sahip doğrulama

Bir seçeneği Exit sub olarak gördüm, ancak bu geçerli sub ie:method-A()'dan çıkacak ve kalan program devam edecektir. Bu işlemin nasıl yapılacağı

. Yorumlarınız sonra

Sub mainMethod() 
    method-A() 
end Sub 

Sub method-A() 
    if (true) Then 
     'Terminate the macro. that is exit method-A() and also mainMethod() 
end Sub 

cevap

14

Düzenleme: TÜM kod sonlandırmak istediğiniz yere Sadece end kullanın.

Sub mainMethod() 
    method_A() 
end Sub 

Sub method-A() 
    if (true) Then End 
     'Terminate the macro. that is exit method-A() and also mainMethod() 
end Sub 

Orjinal Cevap:

Sub mainMethod() 

    'Run the custom function and if it returns false exit the main method 
    If Not method_A Then Exit Sub 

    'If method_A returns TRUE then the code keeps going 
    MsgBox "Method_A was TRUE!" 

End Sub 

Function method_A() As Boolean 
    Dim bSomeBool As Boolean 

    'Code does stuff 
    bSomeBool = True 

    'Check your condition 
    If bSomeBool Then 
     'Set this function as false and exit 
     method_A = False 
     Exit Function 
    End If 

    'If bSomeBool = False then keep going 
End Function 
+0

bu sorun: Eğer Yöntemia bir işlev yapmak yapmak ve aşağıdaki koda göre ana yöntem çıkmak istiyor sanki YANLIŞ bu işlevi dönmek için gereken tüm yaklaşım, birden fazla işlev çağrısı var ve sadece 1 işlev çağrısı değil. Yani bu değişken yaklaşım pratik değil –

+0

Güncellenmiş cevap sonrası ne? – CuberChase

+0

ohhh bu olabilir ... –

İlgili konular