I need the sum of two columns in a view

旧城冷巷雨未停 提交于 2020-01-15 04:57:41

问题


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:


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.



来源:https://stackoverflow.com/questions/555277/i-need-the-sum-of-two-columns-in-a-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!