OK, we have a VFE form that we received from a third party and have been given permission to modify it as we need to and I have discovered a bug in their original design, but yet I cannot figure out why this bug is happening.
Error:
<-BAD VALUE OR BAD INDEX
I have narrowed it down to the gSelfMgmtGoalArray line in the following function FNSMGOALSGETOBSVALUE(nNumber, strType):
{local lIndex
local lObsStr
if (nNumber >5 OR nNumber < 1) then
return ("")
endif
lIndex = fnSMGoalsNameToIndex(strType)
if (lIndex==0) then
return ("")
endif
lObsStr = gSelfMgmtGoalArray[nNumber][lIndex]
if (lObsStr=="") then
return ("")
else
if (obsnow(lObsStr)=="") then
return ("")
else
return(obsnow(lObsStr))
endif
endif}
Here is the fnSMGoalsNameToIndex(strType) function that it calls:
{local lIndex
strType = toupper(strType)
cond
case strType == "GOAL"
lIndex = 1
case strType == "CONFIDENCE"
lIndex = 2
case strType == "FUDATE"
lIndex = 3
case strType == "STATUS"
lIndex = 4
case strType == "COMMENT"
lIndex = 5
case strType == "BEHAVIOR"
lIndex = 6
case strType == "BARRIERS"
lIndex = 7
case strType == "TOOLS"
lIndex = 8
case strType == "TARGET"
lIndex = 9
case strType == "STARTDATE"
lIndex = 10
else
lIndex = 0
endcond
return (lIndex)}
And here is the function that called the FNSMGOALSGETOBSVALUE function:
{ local lCounter
local lValue=""
local lCurrentSummary=""
local lcurrentdiscussion=""
local lStartGoal=""
local lFullSummary = ""
fnSMGoalsInitTermArray()
for lCounter = 1, lCounter <= 5, lCounter = lCounter + 1 do
lCurrentSummary= fnSMGoalsGetObsValue(lCounter, "GOAL")
if (lCurrentSummary == "" or lCurrentSummary=="-") then
continue
else
lstartgoal=match(lcurrentsummary,"~")
lCurrentSummary=sub(lCurrentSummary,lstartgoal+1,size(lcurrentsummary)-lstartgoal)
lCurrentSummary = fmt(lcurrentsummary,"B") + HRET
endif
lValue = fnSMGoalsGetObsValue(lCounter, "TARGET")
if (lValue <> "" and lValue<> "-") then
lCurrentSummary = lCurrentSummary + " Target: " + lValue + HRET
endif
lValue = fnSMGoalsGetObsValue(lCounter, "CONFIDENCE")
if (lValue <> "" and lValue<> "-") then
lCurrentSummary = lCurrentSummary + " Confidence Level (1 = Not Confident to 5 = Very Confident): " + lValue + HRET
endif
lValue = fnSMGoalsGetObsValue(lCounter, "FUDATE")
if (lValue <> "" and lValue<> "-") then
lCurrentSummary = lCurrentSummary + " Follow-Up Date: " + lValue + HRET
endif
lValue = fnSMGoalsGetObsValue(lCounter, "STATUS")
if (lValue <> "" and lValue<>"-") then
lCurrentSummary = lCurrentSummary + " Progress: " + lValue + HRET
endif
lValue = fnSMGoalsGetObsValue(lCounter, "Comment")
if (lValue <> "" and lValue<>"-") then
lCurrentSummary = lCurrentSummary + " Comment: " + lValue + HRET
endif
lValue = fnSMGoalsGetObsValue(lCounter, "BEHAVIOR")
if (lValue <> "" and lValue<> "-") then
lCurrentDiscussion = lcurrentdiscussion + "behavior changes"
endif
lValue = fnSMGoalsGetObsValue(lCounter, "BARRIERS")
if (lValue <> "" and lValue<> "-") then
lCurrentdiscussion = lCurrentDiscussion + if lCurrentDiscussion<>"" then ", " else "" endif + "barriers"
endif
lValue = fnSMGoalsGetObsValue(lCounter, "TOOLS")
if (lValue <> ""and lValue<> "-") then
lCurrentdiscussion = lCurrentDiscussion + if lCurrentDiscussion<>"" then ", " else "" endif + "tools"
endif
if lcurrentdiscussion<>"" then
lCurrentSummary=lCurrentSummary + " Discussed related to this goal: " + lcurrentdiscussion + HRET else "" endif
lCurrentDiscussion=""
if (lFullSummary <> "") then
lFullSummary = lFullSummary + HRET + lCurrentSummary
else
lFullSummary = lCurrentSummary
endif
endfor
return (lFullSummary)}
Can we get the definition for gSelfMgmtGoalArray.
Also, can you run a mel trace when you get the error? This error typically indicates that there is an index out of bounds error so something is calling the array and not finding a value where it expects to see one. If you run the mel trace it might point you toward the issue.
Yes, sorry about forgetting to include this part:
{gSelfMgmtGoalArray = array(array("DMPERSGOAL1","CC GOAL#1 CL","CC GOAL#1 FD","CC GOAL#1 ST","DMbehavGoal1","SM GOAL#1BEH","CC GOAL#1 BA","CC GOAL#1 SM","CCGOAL#1TG","CC GOAL#1 SD"))
insert(gSelfMgmtGoalArray, 2, array("DMPERSGOAL2", "CC GOAL#2 CL", "CC GOAL#2 FD", "CC GOAL#2 ST", "DMbehavGoal2", "SM GOAL#2BEH", "CC GOAL#2 BA", "CC GOAL#2 SM","CCGOAL#2TG","CC GOAL#2 SD"))
insert(gSelfMgmtGoalArray, 3, array("DMPERSGOAL3", "CC GOAL#3 CL", "CC GOAL#3 FD", "CC GOAL#3 ST", "DMBEHAVGOAL3", "SM GOAL#3BEH", "CC GOAL#3 BA", "CC GOAL#3 SM","CCGOAL#3TG","CC GOAL#3 SD"))
insert(gSelfMgmtGoalArray, 4, array("CC GOAL#4", "CC GOAL#4 CL", "CC GOAL#4 FD", "CC GOAL#4 ST", "DMBEHAVGOAL4", "SM GOAL#4BEH", "CC GOAL#4 BA", "CC GOAL#4 SM","CCGOAL#4TG","CC GOAL#4 SD"))
insert(gSelfMgmtGoalArray, 5, array("CC GOAL#5", "CC GOAL#5 CL", "CC GOAL#5 FD", "CC GOAL#5 ST", "DMBEHAVGOAL5", "SM GOAL#5BEH", "CC GOAL#5 BA", "CC GOAL#5 SM","CCGOAL#5TG","CC GOAL#5 SD"))
}
Without being able to review the data being put through a function, index errors are very difficult to resolve. I will suggest that a simple check to ensure the size is what is expected prior to executing a sub() routine is essential in avoiding these errors.
Based on the code, I would suspect that the data length is insufficient for the SUB() function being called. Perhaps putting in a check such as follows (untested):
if lCurrentSummary <> "" and lCurrentSummary >= size(lstartgoal+1) and lCurrentSummary >= size(size(lCurrentSummary)-1) then
lCurrentSummary = sub(lCurrentSummary,lstartgoal+1,size(lcurrentsummary)-lstartgoal)
else
continue
userok("Too small") <-- for debugging purposes only - remove from production code
endif
Ideally, you would consult a MEL trace, search for "ERROR: " and locate the issue immediately and have clear indication as to what the issue is.
Hope this helps.
Thank you, it's been so long since I needed to run a MEL trace that it completely slipped my mind. It probably didn't help that I was delving into this third party's MEL code for days before I got to the point of debugging this particular error. The MEL trace led me right to the issue and I have fixed it now.