I think I found the problem. I had two scoring function in two different forms in the same update. Once I changed the function name for one of the forms both seem to count properly.
Building a score calculation form and I have list box for 8 choices and need for each for to count as 1 when selected. Right now I can only get it to count once even with all selected. Here's the code:
if r4 <> "" then
if r4 = "Arthralgia" or "Uveitis/Iritis" or "Erythema Nodosum" or "Apthous Ulcers" or "Pyoderma Gangrenosum" or "Anal Fissure" or "Draining Fistula (eg;perianal;enterocutaneous;rectovaginal)" or "Perianal Abscess" then
score = 1
else if r4 = "Arthralgia" and "Uveitis/Iritis" then
score = 2
else if r4 = "Arthralgia" and "Uveitis/Iritis" and "Erythema Nodosum" then
score = 3
else if r4 = "Arthralgia" and "Uveitis/Iritis" and "Erythema Nodosum" and "Apthous Ulcers" then
score = 4
else if r4 = "Arthralgia" and "Uveitis/Iritis" and "Erythema Nodosum" and "Apthous Ulcers" and "Pyoderma Gangrenosum" then
score = 5
else if r4 = "Arthralgia" and "Uveitis/Iritis" and "Erythema Nodosum" and "Apthous Ulcers" and "Pyoderma Gangrenosum" and "Anal Fissure" then
score = 6
else if r4 = "Arthralgia" and "Uveitis/Iritis" and "Erythema Nodosum" and "Apthous Ulcers" and "Pyoderma Gangrenosum" and "Anal Fissure" and "Draining Fistula (eg;perianal;enterocutaneous;rectovaginal)" then
score = 7
else if r4 = "Arthralgia" and "Uveitis/Iritis" and "Erythema Nodosum" and "Apthous Ulcers" and "Pyoderma Gangrenosum" and "Anal Fissure" and "Draining Fistula (eg;perianal;enterocutaneous;rectovaginal)" and "Perianal Abscess" then
score = 8
endif
endif
endif
endif
endif
endif
endif
endif
tot_score = tot_score + score
score = 0
endif
In a list box the results save a single string such as "Arthralgia, Uveitis/Iritis" so the same variable cannot be equal to "Arthralgia" and "Uveitis/Iritis", it can be one or the other, or contain both, but not equal to both.
Try something more like this
declare a variable to store the score and start with zero
local score = 0
if a keyword is in the result, add one to score, make as many of these in a row as you need
if match(r4,"Arthralgia")>0 then
score = score + 1
endif
if match(r4,"Uveitis/Iritis")>0 then
score = score + 1
endif
score should have your total at the end
I do something similar in one of my custom forms. I use Yes/No radio buttons to calculate the Revised Cardiac Risk Index score; it works perfectly. Here's the code:
/*
Calculates the RCRI score.
*/
{
local r1
local r2
local r3
local r4
local r5
!IF DOCUMENT.RCRI1 = "" then r1=0
else if (DOCUMENT.RCRI1 = "Yes") then r1=1
else if (DOCUMENT.RCRI1 = "No") then r1=0
else ""
endif
endif
endif
!IF document.rcri2 = "" then r2=0
else if (document.rcri2 = "Yes") then r2=1
else if (document.rcri2 = "No") then r2=0
else ""
endif
endif
endif
!IF document.rcri3 = "" then r3=0
else if (document.rcri3 = "Yes") then r3=1
else if (document.rcri3 = "No") then r3=0
else ""
endif
endif
endif
!IF document.rcri4 = "" then r4=0
else if (document.rcri4 = "Yes") then r4=1
else if (document.rcri4 = "No") then r4=0
else ""
endif
endif
endif
!IF document.rcri5 = "" then r5=0
else if (document.rcri5 = "Yes") then r5=1
else if (document.rcri5 = "No") then r5=0
else ""
endif
endif
endif
!document.cardio_risk = r1+r2+r3+r4+r5
}
Thanks!
Works great for the lstbox, Thanks
gibsonmi said:
In a list box the results save a single string such as "Arthralgia, Uveitis/Iritis" so the same variable cannot be equal to "Arthralgia" and "Uveitis/Iritis", it can be one or the other, or contain both, but not equal to both.
Try something more like this
declare a variable to store the score and start with zero
local score = 0
if a keyword is in the result, add one to score, make as many of these in a row as you need
if match(r4,"Arthralgia")>0 then
score = score + 1
endif
if match(r4,"Uveitis/Iritis")>0 then
score = score + 1
endif
score should have your total at the end
Any thought as to why the calculations will work if done once but when I go back in, It will stick on say a score of 1 and no matter what I choose even if nothing is selected the total score remains 1.
It will update properly until you put the update on hold, then it will not work even when you change the variable? I cant think of a setup where that should happen...
My recommended setup would be something like this in the code panel -
{!document.tot_score} //declare variable
{document.tot_score = FindTotalScore(document.r4)} //set variable on change
{fn FindTotalScore(r4){
...code from above...
}}