我需要视图中两列的总和

时间:2009-02-17 01:52:41

标签: lotus-notes lotus-domino lotusscript

我发现这段代码经过并打印出两列的csv。我后来解析并计算了两列。我想在这里算一下,而不是稍后打印和计数。我一直在四处乱逛,但无法理解。

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

感谢您提前提供任何帮助。

1 个答案:

答案 0 :(得分:3)

尝试这一点,它通过将colval字符串转换为数字值将列累积到rowval中。如果它们是浮点数,你可以很容易地使用double / CDbl()。这假设通过“计算两列”,你的意思是将它们相加并输出总和。如果你的意思是按字面计算,那么将其保留为Integer并更改行

rowval = rowval + CInt(colval)

rowval = rowval + 1

这是:

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

根据您的原始样本,我没有输出任何内容(?)但我会在您应该做的地方发表评论。