Hello, I am trying to change my code to calculate BMI in CM rather than with inches. Here is my inches code on my action button:
{!OBSNOW("BMI",DOCUMENT.BMI_TEMP)}
{!DOCUMENT.BMI_TEMP = fnCalcBMI(OBSNOW("WEIGHT"),lastobsvalue("HEIGHT"))}
{! fn fnCalcBMI(strWgtNow,strHgtAny)
{IF (OBSNOW("WEIGHT") == "" OR OBSANY("HEIGHT") == "" OR OBSANY("HEIGHT") <= 0)
THEN
return ""
ENDIFreturn (str((OBSNOW("WEIGHT") / 2.2) / ((OBSANY("HEIGHT") / 39.4) ^2)))
}
}
{! DOCUMENT.BMI_TEMP}
So does anyone have a code already written that converts CM and pounds to BMI? Thank you in advance! Amy
Nevermind..... I think I found it but I will post in case someone needs it
{fn ccc_BMI_calc()
{
local a,b,c,d,e,f
a = obsany("Height")
b = obsany("Height (cm)")
c = obsany("Weight")
d = obsany("Weight (Kg)")
if (a="" or c="") and (b="" or d="") then userok("There must be a previous Height and current Weight to calculate the BMI.") return "" else
if a="" then e = val(str(b))/2.54 else e = val(str(a)) endif
if c="" then f = val(str(d))*2.2 else f = val(str(c)) endif
return (f / 2.2) / ((e / 39.4)^2)
endif
}
}
But now stuck again- how do I convert inches to cm?
You just reverse what you did to convert cm to inches. Instead of dividing by 2.54, multiply by 2.54.