Field types don't match?

Field types don't match?

Hi,
I am trying to write a function that will go through a set of records and sum a given field (Field B) if criteria for another field is met (Field A).  So if Field A = "Yes" then add Field B to a sum.

Below is a function I use to sum all the values in Field B (Man_Months in this case):
  1. float TotalJobsCon()
  2. {
  3.     countMonths = 0.0;
  4.     for each r in JobCreationSchedule  [Man_Months != 0]
  5.     {
  6.         countMonths = (countMonths  +  r.Man_Months);
  7.     }
  8.     return countMonths;
  9. }
This works perfectly because Man_Months is a float type field.

But When I adapt the function to sum only those fields that fit the criteria I am looking for, I get errors:

  1. float SkilledJobs()
  2. {
  3.     countMonths = 0.0;
  4.     for each r in JobCreationSchedule  [Skill_Level == "Skilled"]
  5.     {
  6.         countMonths = (countMonths  +  r.Man_Months);
  7.     }
  8.     return countMonths;
  9. }
In fact, when I use the script builder to create the "for each record" snippet, it shows an error saying that Man_Months is a string and I cannot proceed.  But it isn't, and the previous function works very well!

Please tell me what I am doing wrong.

Thanks,
Gericke