Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Better way of doing this?

  • 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, Registered Users 2 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, Registered Users 2 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