lotus-noteslotuslotus-formula

Bug in a Dialog List field when using an array in an @For loop


I find an interesting bug in a Dialog List field.

I am trying to create a list of years starting from this year minus 17 and have the list go backwards 30 years. (ex: 2003, 2002, 2001, 2000, ... 1973). I don't want to hardcode the options obviously since every year I would have to go back in and change it.

I created a simple Dialog List field and selected "Use formula for choices" and entered the following formula:

startYear := @Year(@Now)-17; @For( x:=1; x<=30; x:=x+1; temp[x] := startYear-x); temp

When I went to save it, it is rewritten as

startYear := @Year(@Now)-17; @For( x:=1; x<=30; x:=x+1; temp[x := startYear-x ]); temp

Obviously temp[x := startYear-x ] is not going to work but no matter what I try the editor keeps resetting the code to that.

Anyone know of a way to write this type of formula so that it will work and do what I want?

(Notes Designer 9.01 FP8)


Solution

  • First of all to answer your question: Assigning subscript of arrays like you do in Formula is not possible, see this excerpt from designer help (thanx @Richard Schwartz):

    The subscript operator cannot be used on the left side of an assignment statement. That is, you cannot assign a value to a subscripted element. You must build the complete list and then assign it.

    Second: I checked your formula, and if you put it in the "Value"- Formula of a field, then it is not modified by F9, only when putting it in the Dialog List Formula I can reproduce the same behaviour... But I would not mind: As it is not a valid formula at all, this imho can't be called "Bug".

    So here is how your corrected formula could look like:

    _startYear := @Year(@Now)-17; 
    @For( _x:=1; _x<=30; _x:=_x+1; 
        _temp := @Text(_startYear-_x);
        _myArr := @Trim( _myArr : _temp )
    );
    _myArr
    

    Don’t be confused because of the underscores: I use them to distinguish variables from fieldnames. As Dialoglists store text, you need to convert the single values to text. If you want the years in reverse order, then just change one line:

     _myArr := @Trim( _temp : _myArr )
    

    @Formula language -by the way- is quite cool regarding lists and one could have solved this in different ways. E.g. by using daterange and explode:

    _start := @Adjust(@Today;-17;0;0;0;0;0);
    _end := @Adjust(@Today;13;0;0;0;0;0);
    _daterange := @TextToTime( "[" + @Text(_start) + "-" + 
    @Text(_end)+"]");
    _allDates := @Explode( _dateRange );
    @Text(@year(_allDates))
    

    But I admit: as cool as it is, it is not really intuitive, but that would have been the solution in Notes 5 when there was no @For yet.