Tuesday, 3 September 2013

How to handle error for search in c#

How to handle error for search in c#

I created a search application. How would I error trap when something that
I put in the search box is not in the listbox that I have created? the
code for my search is given.
private void btnsearch_Click(object sender, EventArgs e)
{
//if rbnbinary is checked
if (rbnbinary.Checked == true)
{
//start the binary search
BinarySearch(lbxCombined, tbxsearch.Text, 1, 192);
}
//if rbnsequential is checked
if (rbnsequential.Checked == true)
{
//start the sequential search
string target = "";
int n = -1;
bool matchfound = false;
target = tbxsearch.Text;
// start do while loop
do
{
n = n + 1;
//tbxText.Text = x.Tostring();
int result = target.CompareTo(lbxCombined.Items[n]);
//compare function
if (result == 0)
{
matchfound = true;
lbxCombined.SelectedIndex = n;
}
}
while ((matchfound == false) && (n < 192));
}
I tried the
try {}
catch{}
code but it doesn't seem to be working. Could someone help me?
Thanks

No comments:

Post a Comment