使用当前sub以代码的一半退出调用sub

Nee*_*sai 3 vb.net

我使用vs 2008 ..我在vb.net中创建一个Windows窗体应用程序我想要帮助,其中.........如果我退出子*check_fill_for_New()*使用 EXIT SUB然后在*bt_Ok_Click*sub not发一个msgbox ......但它也会退出一半

Public Sub check_fill_for_New()     
    If tb_UserName.Text = "" Then         
        MsgBox("Please Insert User Name Field", MsgBoxStyle.OkOnly, "Error")          
        tb_UserName.Focus()          
        Exit Sub      
     End If
End Sub    

Private Sub bt_Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Ok.Click                
    If maintain_department = "Admin" Then                
        Call check_fill_for_New()                            
        MsgBox("nooooooooo")        
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

Phi*_*rie 6

您需要一个函数,它将返回一个结果,指示您是否要继续调用过程.

Public Function check_fill_for_New() as Boolean
    If tb_UserName.Text = "" Then         
        MsgBox("Please Insert User Name Field", _
                MsgBoxStyle.OkOnly,_
                "Error")   

        tb_UserName.Focus()          
        return True 
    Else
        return False
    End If
End Sub 


Private Sub bt_Ok_Click(ByVal sender As System.Object, _
                        ByVal e As System.EventArgs) Handles bt_Ok.Click   

    If maintain_department = "Admin" Then
        If (check_fill_for_New()) Then
            MsgBox("nooooooooo")        
         End If
    End If
 End Sub
Run Code Online (Sandbox Code Playgroud)

旁注: 似乎您可能不熟悉VB.NET,因为您的命名约定不是.NET框架的标准.看看这里的VB.NET编码约定:http://msdn.microsoft.com/en-us/library/h63fsef3.aspx