none
Limit search to a certain # of results RRS feed

  • General discussion

  • I have a program that searches a webserver for results and I have a combobox with different values for the # of results I want to retrieve from the webserver, however my code isn't working correctly...

     

    Code Block

    private const int RESULTS_PER_QUERY = 20;

    int resultsRequested = 0;

    resultsRequested = int.Parse(comboBox1.SelectedItem.ToString());

    for (int i = 0; i == resultsRequested; i += RESULTS_PER_QUERY)

    {

    //Webserver code here..

    }

     

    It pulls up results in the thousands according to what value I pick in my combobox... The higher the # I pick in the combobox, the higher the results in the thousands i recieve...

    The values in my combobox are:

    10
    20
    30
    40
    50
    75
    100
    125
    150
    175
    200

    Tuesday, November 13, 2007 2:24 AM

All replies

  • Hi Sniper167

    There is one simple work you can do, fetch all the data into a DataTable then assign it to provide say 10 results or use a dropdown and assign its value for the same.

    thanks Smile
    Tuesday, November 13, 2007 5:41 AM
  • Are you sure about that for loop?  Shouldn't it be

    Code Block

    for(int i=0; i<=resultsRequested; i+= RESULTS_PER_QUERY)
    {
     //Web server code here...
    }



    Tuesday, November 13, 2007 6:27 PM
  • One would think... I have tried i<=resultsRequested, i>=resultsRequested, and i==resultsRequested, and the only one that actually works is i<=resultsRequested(and it doesn't even work correctly), the other two don't even search, it doesn't make sense...

     

    I just tried i<=resultsRequested again and searched with the comboBox's value set at 100 and it came up with 3822 results...

    Tuesday, November 13, 2007 9:39 PM
  • Then the problem is within the loop.  Could you share or summarized the code within the loop?
    Tuesday, November 13, 2007 10:07 PM
  • It can't be within the loop, because the search works fine without trying to limit the search... Before I put the combobox in with the limitations, it would give me unlimited results and it worked perfectly... Then my boss told me to put limitations in it with several different options and it stopped working correctly...

    Tuesday, November 13, 2007 11:44 PM
  • Are you sure then that your RESULTS_PER_QUERY variable is accurate then?  There shouldn't be anything wrong with the loop.  It clearly states that you start with i at 0 and increment i by 20 each time the code within the loop runs and it continues to loop until i surpasses the number of results you wanted to collect.  Either your RESULTS_PER_QUERY is incorrect, or you manipulate i or resultsrequested within the loop, those are the only two reasons the loop would not work as expected.
    Wednesday, November 14, 2007 4:34 PM
  • Can I talk to you by email?

    Wednesday, November 14, 2007 11:30 PM
  • Hi Sniper167,

     

    Could you please clarify more details about the limited search to a certain # of the results here? If yes, you will get more helps from the community members. From your description, I can't understand your scenario and what're your issues clearly.

     

    Regards, 

    Thursday, November 15, 2007 5:29 AM
  • What do you want to know about it?

    Thursday, November 15, 2007 11:39 PM
  • Hi Sniper167,

     

    Thanks for your reply.

     

     Sniper167 wrote:

    I have a program that searches a webserver for results and I have a combobox with different values for the # of results I want to retrieve from the webserver, however my code isn't working correctly...

     

    Code Block

    private const int RESULTS_PER_QUERY = 20;

    int resultsRequested = 0;

    resultsRequested = int.Parse(comboBox1.SelectedItem.ToString());

    for (int i = 0; i == resultsRequested; i += RESULTS_PER_QUERY)

    {

    //Webserver code here..

    }

     

    It pulls up results in the thousands according to what value I pick in my combobox... The higher the # I pick in the combobox, the higher the results in the thousands i recieve...

    The values in my combobox are:

    10
    20
    30
    40
    50
    75
    100
    125
    150
    175
    200

     

    From your above description, I have the following doubts and want to confirm with you:

    1) You said "I have a combobox with different values for the # of results I want to retrieve from the webserver", what would like to search from the web server by the selected value of the # of the results?

     

    2)You said "however my code isn't working correctly", could you please clarify what's wrong and what's right for details?

    From your sample codes, I didn't get this.

     

    3) You said "It pulls up results in the thousands according to what value I pick in my combobox.The higher the # I pick in the combobox, the higher the results in the thousands i recieve.". You would like to search in the web server according to the selected value of your ComboBox, how do you do the search in the web server and determine what's wrong and what's right?

     

    I checked your sample codes as follows and couldn't determine what's wrong and what's right:

    Code Block

    private const int RESULTS_PER_QUERY = 20;

    int resultsRequested = 0;

    resultsRequested = int.Parse(comboBox1.SelectedItem.ToString());

    for (int i = 0; i == resultsRequested; i += RESULTS_PER_QUERY)

    {

    //Webserver code here..

    }

     

    Comments:

    Just as BigTuna99 said, it seems there shouldn't be anything wrong with the loop.  It clearly states that you start with i at 0 and increment i by 20 each time the code within the loop runs and it continues to loop until i surpasses the number of results you wanted to collect.  Either your RESULTS_PER_QUERY is incorrect, or you manipulate i or resultsrequested within the loop, those are the only two reasons the loop would not work as expected.

     

    Regards,

     

    Friday, November 16, 2007 7:12 AM