Connecting Tech Pros Worldwide Help | Site Map

Month problem???

Job Lot
Guest
 
Posts: n/a
#1: Jul 21 '05
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

Jakob Christensen
Guest
 
Posts: n/a
#2: Jul 21 '05

re: Month problem???


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:
[color=blue]
> 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
>[/color]
Cor Ligthert
Guest
 
Posts: n/a
#3: Jul 21 '05

re: Month problem???


Jakob,

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

:-)

Cor

"Jakob Christensen" <jch@REMOVEpension.dk>
[color=blue]
> 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:
>[color=green]
>> 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
>>[/color][/color]


Closed Thread