I need the sum of two columns in a view

2019-07-16 07:46发布

I found this code that goes through and prints out csv for both columns. I later parse and count the two columns. I want to count it here instead of printing and counting later. I've been mucking around but couldn't figure it out.

Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim rowstring As String
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView( nameofview )
Set vc = view.AllEntries
Set entry = vc.GetFirstEntry()

While Not entry Is Nothing 
    rowstring = ""
    Forall colval In entry.ColumnValues
        If rowstring = "" Then
            rowstring = colval
        Else
            rowstring = rowstring + +","  + colval
        End If          
    End Forall
Wend

Thanks for any help in advance.

1条回答
Deceive 欺骗
2楼-- · 2019-07-16 08:34

Try this, it accumulates the columns into rowval by converting the colval string into an numeric value. You could just as easily use double/CDbl() if they're floating point. This is assuming that, by "count the two columns", you mean sum them up and output the sum. If you mean literally count, then keep it as an Integer and change the line

rowval = rowval + CInt(colval)

to

rowval = rowval + 1

Here it is:

Dim entry As NotesViewEntry
Dim vc As NotesViewEntryCollection
Dim rowval As Integer                       ' or Double '
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView( nameofview )
Set vc = view.AllEntries
Set entry = vc.GetFirstEntry()

While Not entry Is Nothing 
    rowval = 0
    Forall colval In entry.ColumnValues
        rowval = rowval + CInt(colval)      ' Or CDbl() '
    End Forall
    ' Output rowval here. '
    Set entry=vc.GetNextEntry (entry)
Wend

As per your original sample, I haven't output anything (?) but I've put a comment where you should do it.

查看更多
登录 后发表回答