
Tags:
development
I am subscribed to the
SearchDomino tip newsletters - and sometimes I take the time reading them, as they sometimes have very valuable tips which helped several times to improve my @formula and LotusScript programming. Sometimes I am using an approach because I have used it over and over again, just because it works - without checking if there might a better approach. The tips can help to change that.
Sometimes the tips itself have a similar problem - they work, but there are better ways.
Today is Wednesday - but as DomBlog.de has been (too) quiet for the last few months I think it is time for a show-n-tell Thursday entry. It's about an improvement of the tip
Adding to multi-value fields in LotusScript of Chuck Connell, and to make it easier for me, I'm just copying my comments I have emailed to SearchDomino into this entry.
----------------------------------------------
Hello,
regarding the current searchdomino developer tip:
It is somewhat inefficient to have multiple REDIM Preserve statements.
A better (and shorter) approach would be to REDIM the new array only once, beforehand, as we already know the number of values in the field.
So instead of
If Field.Type = DATETIMES Then
OldTimeList = Field.Values
i = 0
Forall s In OldTimeList
Redim Preserve NewTimeList(i)
NewTimeList(i) = s
i = i+1
End Forall
Redim Preserve NewTimeList(i)
NewTimeList (i) = NewTime
Call ThisDoc.ReplaceItemValue(TIMES_FIELD, NewTimeList)
Else
....
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
we would use
Dim intNewUBound as Integer
If Field.Type = DATETIMES Then
OldTimeList = Field.Values
intNewUBound = ubound (OldTimeList) + 1
Redim NewTimeList(ubound (OldTimeList) + 1)
For i = 0 to ubound (OldTimeList)
newTimeList(i) = OldTimeList (i)
Next
NewTimeList (intNewUBound) = NewTime
Call ThisDoc.ReplaceItemValue(TIMES_FIELD, NewTimeList)
Else ....
An even better (shorter, quicker) approach would be using the ArrayAppend function
If Field.Type = DATETIMES Then
Call ThisDoc.ReplaceItemValue (TIMES_FIELD, ArrayAppend (Field.Values, NewTime))
Else
...
Which is significantly shorter, and faster (which would matter if this function is called repeatedly).