Hello,
I am just about at my wits' end with this form I'm trying to build. I've been creating a behavioral health questionnaire form using a list box to enter the answers, creating functions that put the document variables into arrays, then using COND to convert the strings of my document variables into numeric strings (for example, "Describes me exactly (2)" becomes 2--depending on the questions "Describes me exactly" can also be 0, so I also have a value of "Describes me exactly (0)" that becomes 0--and so on), and adding the sum of the array into a single string and setting to an obs term.
I've managed to get these functions to work to set the obs term for every scoring entry so far...EXCEPT the single score that uses the same document variables as other functions in its array.
So for example, this function works:
{fn MENHLCALC(){
local menhlanswers
menhlanswers = array(DOCUMENT.Q1, DOCUMENT.Q4, DOCUMENT.Q5, DOCUMENT.Q13, DOCUMENT.Q14)
local sum2
sum2 = size(menhlanswers)
local n
local score
local DMNH
n=1
DMNH = 0
local x
WHILE n <= sum2 DO
x = get(menhlanswers,n)
COND
CASE str(x) == "Does not describe me (0)"
score = 0
CASE str(x) == "Describes me exactly (0)"
score = 0
CASE str(x) == "A lot (0)"
score = 0
CASE str(x) == "Somewhat describes me (1)"
score = 1
CASE str(x) == "Some (1)"
score = 1
CASE str(x) == "Does not describe me (2)"
score = 2
CASE str(x) == "Describes me exactly (2)"
score = 2
CASE str(x) == "None (2)"
score = 2
CASE x == ""
USEROK("Missing Answer(s). Please complete and Try Again")
BREAK
ENDCOND
DMNH = DMNH + score
n=n+1
ENDWHILE
obsnow("PSYCHHXQ2",str(DMNH))
}
}
But this one that uses some of the same document variables does not (document variables Q1 and Q4 are repeated):
{fn SECALC(){
local seanswers
seanswers = array(DOCUMENT.Q1,DOCUMENT.Q2,DOCUMENT.Q4,DOCUMENT.Q6,DOCUMENT.Q7)
local sum9
sum9 = size(seanswers)
local n
local score
local DSEL
n=1
DSEL = 0
local x
WHILE n <= sum9 DO
x = get(seanswers,n)
COND
CASE str(x) == "Does not describe me (0)"
score = 0
CASE str(x) == "Describes me exactly (0)"
score = 0
CASE str(x) == "Somewhat describes me (1)"
score = 1
CASE str(x) == "Does not describe me (2)"
score = 2
CASE str(x) == "Describes me exactly (2)"
score = 2
ENDCOND
DSEL = DSEL + score
n=n+1
ENDWHILE
obsnow("PSYCHHXQ6",str(DSEL))
}
}
Any ideas what I'm doing wrong or if a workaround is possible? This is the last thing standing between me and this form being complete.
Thank you!
Posted : August 29, 2017 5:55 am