hello, learner here.

I have a function that checks a textbox for a value if it is below 500 or above 1000 it comes up with a message box. To invoke this I have the function at the top of a action for a button...

void Cal2Click(object sender, EventArgs e)
        {
        WPChk();
        if (port.IsOpen) port.WriteLine("2");
        else MessageBox.Show("Serial port is closed!", "RS232 tester", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

WPChk() is my function to check the value in the text box...

void WPChk()
    	{
    	try
    	{
    	int WhitePointValue;
    	WhitePointValue = int.Parse(WPTarget.Text);
    	
    			if (WhitePointValue > 1000 || WhitePointValue < 500)
    				{	
    				MessageBox.Show("The white point value is out of range. Try a value between 500 and 1000");
    				}
    			else WPTarget.Clear();
    			}
		catch
		{
		MessageBox.Show("Invalid value for whitepoint target");	
		WPTarget.Clear();
		}
    	}

I want the program to stop at that point until a button is pushed again but it just continues. What would you put under WPTarget.Clear(); to halt or am I going about this all the wrong way?

Thanks

return true or false from WPChk() based on success or failure,
on the base of return value of WPChk() you decide whether you want to proceed further or not. ex:

if(WPChk())
{
//do this
}
else
{
//return;
}

ok, I changed it to this

void Cal2Click(object sender, EventArgs e)
        {
        	if(WPChk())
        	{
        	if (port.IsOpen) port.WriteLine("2");
        	else MessageBox.Show("Serial port is closed!", "RS232 tester", MessageBoxButtons.OK, MessageBoxIcon.Error);
        	}
        	else
        	{
        	return;	
        	}
        }

But I got an error "Cannot implicitly convert type 'void' to 'bool' (CS0029)"

Ok, got it. Changed WPChk to bool and had all the results as return false.

Thanks!

This question has already been answered. Start a new discussion instead.