TextBox accepts only 0-24 numbers

Naraayanan
Posted by Naraayanan under C# category on | Points: 40 | Views : 1570
Declaration Part
int[] idx = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
Button_Click Event:
int search_Key = Int32.Parse(txtInput.Text);
int chk_value = SearchText(idx, search_Key);
if (chk_value == -1)
{
txtInput.Text = "";
}
Method:
private static int SearchText(int[] arry,int key)
{

for (int idxs=0;idxs < arry.Length;idxs++)
{
if (arry[idxs] == key)
{
return idxs;
}

}
return -1;
}

Note: It is a windows Application.

Comments or Responses

Posted by: T.saravanan on: 2/5/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Narayanan,

We get the same output from the following simple code...


//Method Calling 

if(!CheckIsNumeric(txtInput.Text))
{
txtInput.Text = string.Empty;
}

private bool CheckIsNumeric(string sText)
{
try
{
if (int.Parse(sText.Trim()) > 24)
{
//MessageBox.Show("Please enter less than 24");
return false;
}
else
return true;
}
catch
{
//MessageBox.Show("Please enter numeric value only");
return false;
}
}

Posted by: Naraayanan on: 2/5/2012 Level:Starter | Status: [Member] | Points: 10
Hi,
Thanks

Login to post response