By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,544 Members | 2,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,544 IT Pros & Developers. It's quick & easy.

Month problem???

P: n/a
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

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
"Job Lot" wrote:
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

Jul 21 '05 #2

P: n/a
Jakob,

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

:-)

Cor

"Jakob Christensen" <jc*@REMOVEpension.dk>
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.
"Job Lot" wrote:
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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.