Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i used vs 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.

VB
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 


VB
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
Posted
Updated 18-Dec-10 7:48am
v2

Convert check_fill_for_New() into a function that returns a boolean and in bt_Ok_Click check for true or false before message. For example:

VB
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 false
 else
  return true
 end if
End Sub 


VB
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
 
Share this answer
 
v2
you can use this code

VB
Public Function check_fill_for_New()
    If tb_UserName.Text = "" Then
        MessageBox.Show("Please Insert User Name Field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
        tb_UserName.Focus()
        Return "False"
    Else
        Return "True"
    End If
End Function

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
            MessageBox.Show("Nooooooooo", "Invalid Username or Password")
        End If
    End If
End Sub
 
Share this answer
 
Comments
Prerak Patel 21-Dec-10 6:54am    
Don't copy answers. Voted 1 for making a working code not working.
dmageiras 22-Dec-10 15:24pm    
I agree with prerakpatel.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900