Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Better way of doing this?

Options
  • 07-03-2008 12:02pm
    #1
    Closed Accounts Posts: 5,240 ✭✭✭


    I have a ComboBox which is populated with 21 different options - Door Server, Call Server ect..

    When a user makes a choice a ListBox is populated with the appropriate data for that selection.

    I have this code in the clickEvent of the ComboBox:
    RangeIndex := cmbRangeSelector.ItemIndex;
    
        case RangeIndex of
          0:
          Begin
              RangeMax := 1;
              RangeMin := 1000;
              PopulateListBox(DataModule1.ADOConnection1, lbEventTypes.Items, RangeMax, RangeMin);
          end;
          1:
          Begin
              RangeMax  := 1001;
              RangeMin  := 2000;
              PopulateListBox(DataModule1.ADOConnection1, lbEventTypes.Items, RangeMax, RangeMin);
          end;
          2:
          Begin
              RangeMax  := 2001;
              RangeMin  := 3000;
              PopulateListBox(DataModule1.ADOConnection1, lbEventTypes.Items, RangeMax, RangeMin);
          end;
          3:
          Begin
              RangeMax  := 3001;
              RangeMin  := 4000;
              PopulateListBox(DataModule1.ADOConnection1, lbEventTypes.Items, RangeMax, RangeMin);
          end;
          4:
          Begin
              RangeMax  := 4001;
              RangeMin  := 5000;
              PopulateListBox(DataModule1.ADOConnection1, lbEventTypes.Items, RangeMax, RangeMin);
          end;
    

    And that carry's on for 21 different selections..., would there be a more effective way of doing this?

    Cheers
    Endo


Comments

  • Registered Users Posts: 515 ✭✭✭NeverSayDie


    Well, the behaviour you've got there seems to be;
    setting RangeMax = 1 + RangeIndex * 1000
    setting RangeMin = (RangeIndex + 1) * 1000

    so, just do that directly instead of through that switch/case construct.

    Edit; yeah, what he said.


  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    It looks to be suitable for a looping statement to me


  • Closed Accounts Posts: 5,240 ✭✭✭Endurance Man


    Bluefrog wrote: »
    It looks to be suitable for a looping statement to me

    Well thats ok :D, just didn't want my code to look cluttered unneccesarily.

    Cheers


Advertisement