Month problem???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two ComboBox on a form both holding list of months in a year (Jan –
Dec).
I wan to calculate number of months between Month selected in first combobox
and Month selected in second combobox.

For instance,
If first combobox has July selected and second combobox had June selected
then number of months should be 12.

Similarly if first combobox had Oct selected and second combobox has Dec
selected then number of months should be 3.

Please help, I am stuck on this…. Thanx
 
Assuming that you have added the twelve months to comboBox1 and comboBox2,
the following code should do the trick:

int m1 = 1 + comboBox1.SelectedIndex;
int m2 = 1 + comboBox2.SelectedIndex;
int diff = m2 - m1 + 1;
if (m2 < m1)
diff += 12;

HTH, Jakob.
 
Jakob,

Nice and simpel, I was thinking completly in the wrong direction

:-)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top