Hey, i was wondering if there was a way to do a custom error check. Such as if a user inputs anything other than a number then i would like it to output an error message. short of having to type in every letter and symbol on the keyboard is there a quick and efficient way of doing this?
i know like in php if you run a bad query or something doesnt go quite as planned you can do a
or die mysql_error()
or something to that effect.
just wondering if there was the same for C #
here is what i am talking about:
//clear the various boxes
lstNetAdd.Items.Clear();
txtCIDR.Text = "";
txtSubNetShown.Text = "";
txtBitsBorrow.Text = "";
//pull the value into the variable
double dblSubnetsNeeded, dblBitsToBorrow, dblNET4;
dblSubnetsNeeded = Double.Parse(txtSubnetsNeeded.Text);
//if they only need one subnet what to do
if (dblSubnetsNeeded <= 1 || dblSubnetsNeeded >= 256)
{
//Value to high or too low
MessageBox.Show("Please Enter a Value Betweeen 2 and 255", "Error: Value Range", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//what to do if they want more than one
else
{
//determin number of bits to borrow
dblBitsToBorrow = Math.Log(dblSubnetsNeeded)/Math.Log(2);
//Declare Variables to Handle left over bits
decimal decBitsToBorrow = Convert.ToDecimal(dblBitsToBorrow),
decBitsLeftOver;
//Mod out the decimal
decBitsLeftOver = (decBitsToBorrow % 1);
//if there are decimal places
if (decBitsLeftOver > 0)
{
//remove the decimal places, incriment the bits by one and then convert for display
decBitsToBorrow = decBitsToBorrow - decBitsLeftOver;
decBitsToBorrow += 1;
Convert.ToString(decBitsToBorrow);
}//endif
//display the bits to borrow
txtBitsBorrow.Text = String.Format( "{0:0}", decBitsToBorrow);
//display the current subnet
dblBitsToBorrow = Convert.ToDouble(decBitsToBorrow);
//determin the subnet
dblNET4 = 256 - ((Math.Pow(2, 8)) - (Math.Pow (2, (8-dblBitsToBorrow))));
/* the following section will display the first few results of the subnet addy */
//variables for the first subnet, counter and highest subnet
double dblFirstNET4 = dblNET4 - dblNET4,
dblNETStore = dblNET4,
dblHighestSubnet = 255 - dblNET4;
//display first and second subnets
lstNetAdd.Items.Add( "192.168.1." + dblFirstNET4);
lstNetAdd.Items.Add( "192.168.1." + dblNET4);
/*end pre-address display*/
/*Now itterate through the last of the subnets*/
//only work untill we are are less than highest subnet
while (dblNET4 < dblHighestSubnet )
{
//increment the subnet by one and display the subnet
dblNET4 = dblNET4 + dblNETStore;
lstNetAdd.Items.Add( "192.168.1." + dblNET4);
}
/*end itteration*/
/*Show CIDR notation and #of Subnets*/
decimal decCIDR = 24 + decBitsToBorrow;
txtCIDR.Text += "/";
txtCIDR.Text += String.Format( "{0:0}", decCIDR);
txtSubNetShown.Text = Convert.ToString(lstNetAdd.Items.Count);
/*end CIDR and subnets*/
}//endif
on the top section where it says
dblSubnetsNeeded = Double.Parse(txtSubnetsNeeded.Text);
i want to write an error check that will output a message if the user does not input a proper integer value