Q

Export values

Is there a way to get a total of the values that you are exporting in a LotusScript? It goes through and gets each employee hours, but then how do I total all employees?

This Content Component encountered an error
Is there a way to get a total of the values that you are exporting in a LotusScript? It goes through and gets each employee hours, but then how do I total all employees?

Here is my script:

Dim s As New notessession
Dim db As notesdatabase
Dim view As NotesView
Dim item As NotesItem
Dim doc As NotesDocument
Dim nbcol As Integer
Dim newline As String
Dim fileName As String
Dim fileNum As Integer
Dim dateTime As New NotesDateTime("" )
dateTime.LSLocalTime = Now
Dim dateTime1 As NotesDateTime
Dim adocCollection As NotesDocumentCollection
Dim username As String

 
Set db = s.CurrentDatabase
Set view = db.GetView("ExportPayCor")
 
 
view.AutoUpdate = False
 
'need to create a date for export
Dim chdt As String
chdt = dateTime.DateOnly
Set doc = view.GetFirstDocument
 
 
'this is to grab the date from the timesheet and all other dates for PTO Exempt
Set item = doc.GetFirstItem("Date1")
Set dateTime1 = item.DateTimeValue
Dim date1value As Variant
date1value = doc.Date1(0)
Dim date2value As Variant
date2value = doc.Date2(0)
Dim date3value As Variant
date3value = doc.Date3(0)
Dim date4value As Variant
date4value = doc.Date4(0)
Dim date5value As Variant
date5value = doc.Date5(0)
Dim date6value As Variant
date6value = doc.Date_1(0)
Dim date7value As Variant
date7value = doc.Date_2(0)
Dim date8value As Variant
date8value = doc.Date_3(0)
Dim date9value As Variant
date9value = doc.Date_4(0)
Dim date10value As Variant
date10value = doc.Date_5(0)
 
fileName2 = Inputbox$("Enter your file name")
 
fileName = "K:ShareCindy" + fileName2 + ".txt"
fileNum = Freefile()
Open fileName For Output As fileNum
 

Print #fileNum, "H"; "PAYCOR01" ;chdt;"DominoDB               ";"N";doc.DepDate(0)
 
While Not (doc Is Nothing)
'good this works 8/29/06
If doc.Dept(0) = "Info Technology" Then
If doc.FWPagerM(0) > 0 Or doc.NWPagerM(0) > 0 Then
Print #fileNum, "D"; "000" + doc.EmpNo(0); " "; doc.TTReg(0);"    ";"     ";"     ";"    ";"     ";"    ";"     ";"    ";"       ";"1";"BW"
    
 End If
Else
Print #fileNum, "D"; "000" + doc.EmpNo(0); " "; doc.TTReg(0);"    ";"     ";"     ";"    ";"     ";"    ";"     ";"    ";"       ";" ";"BW"
 End If
  
If doc.TPTO(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTPTO(0) + "PTO"
End If
If doc.TOverTime(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTOverTime(0) + "OT"
End If
If doc.TFloat(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTFloat(0) + "Float"
End If
If doc.THoliday(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTHoliday(0) + "Hol"
End If
If doc.TJury(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTJury(0) + "Jury"
End If
If doc.TOtherPd(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTOtherPd(0) + "OPD"
End If
If doc.TDoubleTime(0) > 0 Then
Print #fileNum, "D";"000" + doc.EmpNo(0);" ";doc.TTOtherPd(0) + "OPD"
End If
Absolutely. (PATTERN?).

I'm not 100% clear on all the details of what your code is doing, but it looks like essentially, you are writing a report that a view cannot provide and you want to create totals.

What you want to do is place your "Print' statement in a subroutine. And for this to work, the file you are writing to will have to be available across calls to the subroutine. Now the most obvious ways to do this are by using a global variable or by passing the file to the subroutine. Now you may be asking, "How can I pass an open file to a subroutine?" Well you can't. But you CAN pass a stream.

As you probably know, global variable are BAD and you should almost never use them. However, global variables are useful for the kinds of data that, in object-oriented programming, would be a class property. LotusScript supports object-oriented programming sort of, but its support is so minimal that almost no one uses it. Generally, what you do instead is create a Script Library to act like a class (or more like a Unit in Pascal). Here is how to create on to add your totals.

  1. Create a new script library. Name it "Reporter."
  2. In the "Options" section of the library, comment out the "Option Public." It is bad programming style to publicly expose code by default (in any language). As is so often this case in Notes, you should ALWAYS turn off this default and instead explicitly declare subroutines as public when they need to be public.
  3. In the declarations section of the library, add the following code to define a stream and the counters needed for your totals:
Dim session As NotesSession
  Dim stream As  NotesStream
  Dim totalPTO As Integer
  ' . . . other counters go here . . .  
  1. In the library's Initialize event, add the code "Set Session = New NotesSession." The initialize event will take the place of an object constructor.
  2. Now create a subroutine called "BeginReport." Since we cannot pass anything to the initialize event (like we can in a real object constructor in most languages) we need our own routine to initialize our "class"):
     Public Sub  BeginReport(ByVal  pathName As String)
     stream = session.CreateStream
  Call  stream.Open(pathname, "ASCII")
  totalPTO=0
   End Sub 
  1. Now add another subroutine to write each line:
  Private Sub WriteEntry(ByVal empNo As String,
        ByVal cat As String, ByVal amt As Double)
    ' Since you were using Print #, instead of "Wrtie #" 
    'no delimiters are written to the file but you can add
    'commas and tabs chr(9) or whatever you may need.
    'You can also break the call up into multiple calls as 
    Call stream.WriteText("D" + "000" + empNo + " ", EOL_NONE)
    Call stream.WriteText(Format(amt, "$99,990.00") + cat, EOL_CRLF)
    Select Case category
      Case "PTO"
        totalPTO = totalPOT + amount
  . . .
    End Select
  End Sub
  1. And finally, add one more subroutine to close the stream.

Now, I've obviously made this a little more complex than it has to be so I can illustrate how to set up a "unit" in a LotusScript Library. But using it is simple.

  1. In the "Options" section of your agent, assign a Use "Reporter" to reference the script library.
  2. Instead of opening a file, call BeginReport.
  3. Instead of printing to the file, call WriteEntry.

And in practice, you will no doubt want to add one more routine to the library to print or otherwise return the totals, but I'll leave that as an exercise. You can also use a LotusScript list for a more generic set of counters without having to manually create each counter and use a select case as I have done here. If I have a chance I'll talk about lists in an up coming Blog.

This was first published in September 2006

Dig deeper on LotusScript

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close