Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How do i exit from the Handler in case the function finds an error in the user input?

$
0
0

Hi,

I have a question about how to stop a running script after input validation function was executed.

Function InputValidation($objTextBoxServer_text)

    {

         if (($objTextBoxServer_text -eq "") -or ($objTextBoxServer_text -eq "Enter DB address"))

                {

                try {

                [System.Windows.Forms.MessageBox]::Show("Server Name or IP is missing" , "Error" , 0) 

                     }

                Catch 

                    {

                    exit 

                    }

                }

    }

$handler_button_Step1 = {

#code is here

InputValidation "$objTextBoxServer"   #activating the function

#more code is in here

}

The problem is that when "IF" part of the function is true, the "more code" part is being done anyway. 

Why is that? How do i exit from the Handler in case the function finds an error in the user input?  any suggestion?

Daniel

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles