Re: Exiting a Subroutine

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hey,

You can use the return keyword for this:

if (this.txtFirstName.Text == "")
{
MessageBox.Show("First Name is required");
this.txtFirstName.Focus();
return;
}

Hope that helps,
Clint

OutdoorGuy wrote:
> Greetings,
>
> I'm still relatively new to C# and was wondering if there was a way
to
> exit a subroutine (such as "Exit Sub" in VB)? I have the code below
> which performs validations. If the user fails to enter in a First
name,
> then I want to set the focus to the control on the form and then exit
> the subroutine. Any ideas?
>
> private void btnSubmit_Click(object sender, System.EventArgs e)
> {
> ..
>
> if (this.txtFirstName.Text == "")
> {
> MessageBox.Show("First Name is required");
> this.txtFirstName.Focus();
> // I then want to exit the subroutine.
> }
> if (Lastname == "")
> {
> ..
>
> Thanks in advance!
>
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***

.



Relevant Pages

  • Re: string
    ... and put the parts of the returned value into a string. ... In this case - a dos .com file, ... so after having printed VendorStr twice, you exit normally - without ... call subroutine ...
    (alt.lang.asm)
  • Re: Adding pre/post escape sequences to a "SAY"
    ... $SAY = "WRITE SYS$OUTPUT" exists on pretty much every VMS system, ... The one thing I could think of is to define a subroutine: ... Unofficial OpenVMS Hobbyist Support Page: ...
    (comp.os.vms)
  • Re: die unless match is successful
    ... I want the below if loop to end if it cannot find any match & print the ... However it just exit without hitting my "die" ... chomp $line; ... You shouldn't use an ampersand when you call a subroutine: ...
    (perl.beginners)
  • Re: Inappropriate ioctl for device
    ... I understand that die() exits the program. ... assignment to a variable to hold that exit error, ... What does `shift` do? ... scalars that was passed to the subroutine. ...
    (perl.beginners)
  • Re: Error handling in C
    ... using exit() to deal with a problem is seldom the ... mainmight, in some other program, become a subroutine of main. ... I have found that discussing EH is difficult without a given context. ... as stylistic techniques that are context (program type or ...
    (comp.lang.c)