hello everyone,
i’ve got this nasty problem:
I have a listbox on my form that contains a list of entry’s (values from other documents). When there is one entry selected i want to get the value of the previous entry from the list.
what i want to do is the following:
(value of selected item) + (value of previous item) / 2
this all has to happen in a computed field.
But i can’t get the values right, tPrevious1 (the value of the previous entry) always gives back ‘-1’
Can anyone please look at my code and tell me what’s wrong??
My code is as follows:
FIELD List := List;
tList := List;
tSelected := @TextToNumber(Plaats);
MEM := @Member(@Text(tSelected);@Text(tList));
tPrevious1 := @If(MEM=1;0;@Member(@Text(tSelected);@Text(tList))-1);
WAARDE :=
@If(tPrevious1=0;
tSelected-1;
(tselected +
@TextToNumber(
@Subset(
@Subset(@Text(tList);tPrevious1)
;-1)
))
/2);
FIELD nr := nr;
@While(@contains(@text(tlist);@text(waarde));
waarde = waarde -1);
@If(nr=waarde;“”;
@SetField("nr"; @Text(waarde)))
- the while loop also doesn’t work and gives me the ‘formula has exceeded maximum memory usage’ error…
Thanks in advance for any suggestions!
cheers,
Sander
Subject: getting previous value from a list and writing that to a field
Hi Sander,
What about:
tList := @Text(List);
tSelected := @Text(Plaats);
tIndex := @Member(tSelected;tList)
tPrevious := @If(tIndex!=1;@GetMembers(tIndex;tList);“”);
tWaarde :=
@If(tPrevious=“”;
@TextToNumber(tSelected-1);
(@TextToNumber(tSelected) + @TextToNumber(tPrevious))/2
)
About the @While shouldn’t you use waarde := waarde - 1??? So := instead of =
Good luck!
Subject: RE: getting previous value from a list and writing that to a field
Also if you test a list for a value use @IsMember instead of @Contains…
Subject: This should work…
tList := @Text(List);nSel := @TextToNumber(Plaats);
MEM := @Member(Plaats; tList);
tPrev := @If(MEM=1;“0”; @SubSet(@SubSet(tList; Mem -1); -1);
nPrev := @TextToNumber(tPrev);
WAARDE := @If(MEM = 1; nSel - 1; (nSel + nPrev) /2);
tWar := @Text(WAARDE);
@While(@contains(tList; @Text(waarde)); waarde := waarde -1);
FIELD nr := @Text(waarde);
If you are using R6 could be a little easier:
tList := @Text(List);
nSel := @TextToNumber(Plaats);
MEM := @Member(Plaats; tList);
tPrev := @If(MEM=1;“0”; tList[Mem -1];
nPrev := @TextToNumber(tPrev);
WAARDE := @If(MEM = 1; nSel - 1; (nSel + nPrev) /2);
tWar := @Text(WAARDE);
@While(@contains(tList; @Text(waarde)); waarde := waarde -1);
FIELD nr := @Text(waarde);
Subject: RE: This should work…
this gives me the error:
“Array index out of bounds” any suggestions??
Subject: Let me know if my assumptions are wrong…
You have a field called “List” computed w/ @DbColumn(…) to retrieve the values. You have a Listbox field called “Plaats” with the choices coming from “List”? Lets put some debug in…
tList := @Text(List);
nSel := @TextToNumber(Plaats);
@Prompt([OK]; “Debug”; "Plaats = " + Plaats);
MEM := @Member(Plaats; tList);
@Prompt([OK]; “Debug”; "MEM = " + @Text(MEM));
tPrev := @If(MEM=1;“0”; tList[Mem -1];
nPrev := @TextToNumber(tPrev);
WAARDE := @If(MEM = 1; nSel - 1; (nSel + nPrev) /2);
@While(@contains(tList; @Text(waarde)); waarde := waarde -1);
FIELD nr := @Text(waarde);