views:

501

answers:

1

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.

+2  A: 

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.

paxdiablo
Thank you. Sorry I should have been more specific because I meant sum of the two columns. Ok, so does this mean the rowval is a two-celled array with both sums inside? How do I have two integer variables equal to each sum?
Todd
I'm trying to email the each of the column sums. I tried putting Call rtitem.AppendText ( rowval )and the agent doesn't run all the way through. Any thoughts as to why this would happen?Thanks again for your help.
Todd
In answer to your first, rowval is initialized for every row then it has colval added to it. Where it says "output rowval here", that's where you have to process rowval for that row just done.
paxdiablo
In answer to (2), I've just noticed the infinite loop (which I copied from your original code) - see update just before Wend where it advances to next row.
paxdiablo
Thank you it works! I put in filesprocessed = filesprocessed + rowval in the ' Output rowval here. '. This is what I don't understand. I'd like to be able to sum up each column individually. I tried specifying the first column by saying entry.ColumnValues(0) but it doesn't work. Any ideas?
Todd
Alrighty I figured it out!While Not entry Is nothingrowval = 0errors = 0Forall colval In entry.ColumnValuesIf rowval > 0 Thenerrors = Cint(colval)Elserowval = Cint(colval)End ifEnd Forallfilesprocessed = filesprocessed + rowvalerrorstotal = errorstotal + errorsetcThanks for your help!
Todd
Why wouldn't you just add a column that sums the programmatic names of the other two columns and then put totals on it? Then a simple File - Export of the view is all that is needed.
Peter LaComb Jr.
@Peter, you don't always have control of the Notes DB schema, even if you can write agents for it.
paxdiablo