Manage Learn to apply best practices and optimize your operations.

Write Out Field Values To A Csv File

This little workhorse takes a view of your choice, an array of field names, and
a filename, then gets the value of those items and writes them to a file in CSV
format. If nothing is found in the view, it returns false.
Enjoy!
Function WriteValuesToFile(viewTarget As NotesView, varFieldNames As
Variant,strFileName As String) As Integer
Dim intFileNum As Integer
Dim intArraySubscript As Integer
Dim vecViewTarget As NotesViewEntryCollection
Dim ventViewTarget As NotesViewEntry
Dim docViewTarget As NotesDocument
Dim strFieldName As String
Const Quote = {"}
Const Delim = {,}
Const EndLine = {;}

Set vecViewTarget = viewTarget.AllEntries

If vecViewTarget.count < 1 Then 'Check for values to retrieve before opening a
file handle

WriteValuesToFile = False
Exit Function

Else
WriteValuesToFile = True
End If

intFileNum = Freefile()

Open strFileName For Output As #intFileNum

Set ventViewTarget = vecViewTarget.GetFirstEntry 'Get 1st entry in view

Do While Not ( ventViewTarget Is Nothing) ' for all the documents in the
view, print out the desired field values to the file
Set docViewTarget = ventViewTarget.Document
strDocRecord = ""
For intArraySubscript = 0 To Ubound(varFieldNames)

strFieldName = varFieldNames(intArraySubscript)

Set itmNeeded = docViewTarget.GetFirstItem(strFieldName)

If strDocRecord = "" Then

strDocRecord = Quote & itmNeeded.text & Quote
Else


strDocRecord =strDocRecord & Delim & Quote & itmNeeded.text & Quote

End If


Next intArraySubscript
strDocRecord =strDocRecord & EndLine 'Here is the whole delimited string to
go on a line in the file
Print #intFileNum, strDocRecord


Set ventViewTarget = vecViewTarget.GetNextEntry(ventViewTarget)
Loop


Close #fileNumInt

End Function

Dig Deeper on Domino Resources - Part 5

SearchWindowsServer
Search400
  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

SearchDataCenter
SearchContentManagement
Close