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

时间:2010-12-18 17:31:42

标签: vb.net

我使用v s 2008 .. 我在vb.net中创建一个Windows窗体应用程序 我想要帮助.........如果我退出sub * check_fill_for_New()*使用 EXIT SUB 然后在* bt_Ok_Click * sub中不会触发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

1 个答案:

答案 0 :(得分: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

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