0

I need your help to resolve my problem.

I have a ComboBox with 2 items: StackExchange, and StackOverflow.

I want to know how to count of how many times StackOverflow item was selected and put the results in a messagebox.

Thanks and Regards.

July Elizabeth
  • 105
  • 1
  • 11

1 Answers1

0

Create an array of two int values, initialized to 0s. In the TComboBox::OnSelect event, increment the appropriate array item based on the index reported by the TComboBox::ItemIndex property.

private:
    int Counters[2];

void __fastcall TMyForm::ComboBox1Select(TOBJECT *Sender)
{
    Counters[ComboBox1->ItemIndex]++;
}

void __fastcall TMyForm::DisplayCounts()
{
    String Msg;
    Msg.sprintf(_D("%s: %d\n%s: %d"),
        ComboBox1->Items->Strings[0].c_str(), Counters[0],
        ComboBox1->Items->Strings[1].c_str(), Counters[1]
    );
    ShowMessage(Msg);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • All the praises and thanks be to the God!. Like your answers beforehand, this answer is also works perfectly. You're so great, indeed. Thank you very...really much, Remy!. – July Elizabeth May 02 '16 at 09:43