2010-12-18 61 views
3

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

回答

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 

旁注:看来,作为您的命名约定是不是与.NET Framework标准则可能是新的VB.NET。看看这里的VB.NET编码约定:http://msdn.microsoft.com/en-us/library/h63fsef3.aspx