我需要一个视图中两列的总和 [英] I need the sum of two columns in a view
问题描述
我发现这段代码可以遍历并打印出两列的csv.我稍后解析并计算两列.我想在这里计算而不是以后打印和计数.我一直在乱搞,但无法弄清楚.
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.
推荐答案
尝试一下,它通过将colval字符串转换为数值,将列累积为rowval.如果它们是浮点数,则可以轻松地使用double/CDbl().假设通过计算两列",您的意思是将它们加起来并输出总和.如果您是按字面意思计数,则将其保留为Integer
并更改行
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)
到
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
根据您的原始样本,我没有输出任何内容(?),但我已在您应该执行的操作中添加了注释.
As per your original sample, I haven't output anything (?) but I've put a comment where you should do it.
这篇关于我需要一个视图中两列的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!