在代码的一半处使用当前子项退出调用子项 [英] exit a calling sub using current sub at half of a code

查看:96
本文介绍了在代码的一半处使用当前子项退出调用子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是2008年..
我在vb.net中创建Windows窗体应用程序
我需要帮助...如果我使用
退出子check_fill_for_New() 退出子,然后在bt_Ok_Click子中不触发msgbox……但它也会退出一半.

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.

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

推荐答案

check_fill_for_New()转换为一个返回布尔值的函数,并在bt_Ok_Click中在消息之前检查是否为true或false.例如:

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:

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 





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


您可以使用此代码

you can use this code

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


这篇关于在代码的一半处使用当前子项退出调用子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆