Search code examples
lotus-noteslotusscript

Most commonly used word in column of a view


Is there a way to get the most commonly used word from a view.. For example, if I have a column with names like this

NAME
John
Mary
Jane
Alan
John
Laura
John  

It will return John because it is the name that appears the most.

Added...

I don't mind using another view as suggested by @Richard Schwartz. In fact, I created it and tried something similar but a little different than your first suggestion.

Here is my code, but it doesn't return the correct value:

Dim var As Variant
Set view1 = db2.getView("pomoc")
var=view1.GetColumnValues(0)
max=-1
field=""
Forall id In var
    Set ve=view1.GetEntryByKey(id)
    num=ve.ChildCount
    If num>max Then     
        max=num
        field=id
    End If  
End Forall

And I also want to register the entries that are used the same number of times


Solution

  • Are you okay with adding another view? Make it categorized, and then write your code to use a NotesViewNavigator to walk the categories, looking for the NotesViewEntry with the highest ChildCount.

    If you are unable to add another view, then you will probably have to use a List:

    dim names List as integer
    

    Then write your code to get NotesView.AllEntries, use GetFirstEntry and GetNextEntry to walk the NotesViewEntryCollection, and for each NotesViewEntry execute statements like this:

    thisName = thisEntry.ColumnValues(N)
    names(thisName) = names(thisName) + 1 
    

    Where N is the columnn containing the names.

    After you've processed the entire view, do something like this:

    maxCount = 0
    maxName = ""
    forall nameCounter in names
     if nameCounter > maxCount then
       maxCount = nameCounter
       maxName = listtag(nameCounter)
    end forall
    

    When this exits, maxName will be the most common name, and maxCount will be the number of occurrances.