Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exit a calling sub using current sub at half of a code

Tags:

vb.net

i used v s 2008.. i create a windows form application in vb.net i want help in which .........if i exit a sub *check_fill_for_New()* using EXIT SUB then in *bt_Ok_Click* sub not fire a msgbox......but it will also EXIT at half

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
like image 225
Neel Desai Avatar asked Dec 31 '25 01:12

Neel Desai


1 Answers

You need a function that will return a result indicating if you want to continue from your calling procedure.

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

Side note: It seems that you might be new to VB.NET as your naming conventions is not standard with the .NET framework. Have a look at the VB.NET coding conventions here: http://msdn.microsoft.com/en-us/library/h63fsef3.aspx

like image 71
Philip Fourie Avatar answered Jan 06 '26 07:01

Philip Fourie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!