Page 1 of 1

put the round of 2.2 <> 2 Help

Posted: Thu Mar 12, 2015 7:22 pm
by DavJans
Below is my code that I cant get to work, I have an if/then that should in my mind change the color to yellow. However it seems that the round of a number does not equal the same number. if you look at case "4" i just both aAvg and Top52 next to each other and they both are 2 but still no yellow.

Code: Select all

on updateTop5WelderMonth
   put revOpenDatabase("MySQL",dbAddr,dbName,dbUser,dbPass) into tResult
if tResult is a number then
        put tResult into gConnectionID
    else
        put empty into gConnectionID
        answer error "Unable to connect to the database:" & cr & tResult
BREAK
end if
   
   put "SELECT cworker, Count(*) FROM nonc WHERE cworker REGEXP '^[0-9]+$' and cat = 'welder' and errordate > DATE_SUB(NOW(), INTERVAL 1 MONTH) group by cworker order by count(Cworker) desc" into tSQL
   put revDataFromQuery(comma, cr, gConnectionID, tSQL) into Top5WMonth
   put 1 into Top5M
   put "0" into AllTimeAvg
   put "0" into TotalEmp
   repeat for each line tLine in Top5WMonth
      put item 2 of tLine into TopAvg
      put AllTimeAvg + TopAvg into AllTimeAvg
      put TotalEmp + "1" into TotalEmp
   end repeat
   put AllTimeAvg / TotalEmp into aAvg
   put the round of aAvg into aAvg
   put "Avg/Emp = " & aAvg & " pink slips" into fld "Top10MWA"
   repeat for each line tLine in Top5WMonth
          put item 1 of tLine into Top51M
          put item 2 of tLine into Top52M
   switch Top5M
      case "1"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top1MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top1MW" to green
            else
               set the backgroundColor of fld "Top1MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top1MW" to yellow
            end if
         break
         
      case "2"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top2MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top2MW" to green
            else
               set the backgroundColor of fld "Top2MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top2MW" to yellow
            end if
         break
         
      case "3"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top3MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top3MW" to green
            else
               set the backgroundColor of fld "Top3MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top3MW" to yellow
            end if
         break
                  
      case "4"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top4MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top4MW" to green
            else
               set the backgroundColor of fld "Top4MW" to red
            end if
            put aAvg into fld "Field1"
            put Top52M after fld "Field1"
            if aAvg = Top25M then
               set the backgroundColor of fld "Top4MW" to yellow
            end if
         break
                  
      case "5"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top5MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top5MW" to green
            else
               set the backgroundColor of fld "Top5MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top5MW" to yellow
            end if
         break
         
         case "6"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top6MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top6MW" to green
            else
               set the backgroundColor of fld "Top6MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top6MW" to yellow
            end if
         break
         
      case "7"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top7MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top7MW" to green
            else
               set the backgroundColor of fld "Top7MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top7MW" to yellow
            end if
         break
         
      case "8"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top8MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top8MW" to green
            else
               set the backgroundColor of fld "Top8MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top8MW" to yellow
            end if
         break
                  
      case "9"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top9MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top9MW" to green
            else
               set the backgroundColor of fld "Top9MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top9MW" to yellow
            end if
         break
                  
      case "10"
         put "Employee " & Top51M & " has " & Top52M & " pink slips" into fld "Top10MW"
         if aAvg > Top52M then
               set the backgroundColor of fld "Top10MW" to green
            else
               set the backgroundColor of fld "Top10MW" to red
            end if
            if aAvg = Top25M then
               set the backgroundColor of fld "Top10MW" to yellow
            end if
         break
         
   end switch
   put Top5M + 1 into Top5M
     end repeat
       if gConnectionID is a number then
        revCloseDatabase gConnectionID
        put empty into gConnectionID
    end if
end updateTop5WelderMonth

Re: put the round of 2.2 <> 2 Help

Posted: Thu Mar 12, 2015 8:48 pm
by DavJans
I tied again, made a new stack with the following code and it works fine as expected, what is wrong in my original code?

Code: Select all

on mouseUp
   put the round of fld "Dec" into roundedDec
   put roundedDec into fld "Rounded"
   put fld "Whole" into wholeWhole
   put wholeWhole into fld "Whole2"
   if fld "Rounded" = fld "Whole2" then
      set the backgroundcolor of btn "fld" to yellow
   else
      set the backgroundcolor of btn "fld" to red
   end if
   if roundedDec = wholeWhole then
      set the backgroundcolor of btn "var" to yellow
   else
      set the backgroundcolor of btn "var" to red
   end if
end mouseUp