Import Formated Text File As You Want !

If you want to import a formated text file and make from it documents, the
easyest way is to create a view and use the import basic tool of Notes. But
this is not very convinient.
What I propose is a Class that handle everything to import AND export documents
from and to text file.

HOW DOES IT WORKS :

_ Methods:
ImportAll
ExportAll
ExportOneDoc
GetFirstRecord
GetNextRecord
New
Delete

-Creation
To create a new SeqFile object, use the New method :
-Syntax:
Dim variableName As New SeqFile(fileName , openMode , fields , fieldType ,
separator , dstart , dstop)
or
Set notesDocument = New SeqFile(fileName , openMode , fields , fieldType ,
separator , dstart , dstop)

-Parameters:
fileName: Path & file name of the text file (string)
openMode: Type of action to perform. Values are IMPORT or EXPORT
fields: array of field name to export (in order) (string())
fieldType: array of the type of the fields sp?cified in "fields" (same order)
(string())
separator: a string to specify the field separator
dstart : delimiter to begin a field (string)
dstop : delimiter to end a field (string)

------------------
ImportAll method

Import all records of a text file as defined in a configuration document.
Multiple values are allowed.

Syntax :
Call SeqFile.ImportAll(form as string)
Parameters :
in: form, form to use to create the documents

----------------
ExportAll method

Export all records of a text file as defined in the SeqFile Object.

Syntax:
Call SeqFile.ExportAll ( docCollection as NotesDocumentCollection )

Parameters:
in: docCollection, collection of documents to export

-------------------
ExportOneDoc method

Export one document in the a text file as a record.

Syntax:
Call SeqFile.ExportOneDoc( doc as NotesDocument )
Parameters:
in: doc, document to export

---------------------
GetFirstRecord method

Get the first Record in the text file and converts in a NotesDocument

Syntax:
Set document = SeqFile.GetFirstRecord()
Parameters: nothing
Return value:The converted document (NotesDocument)

--------------------
GetNextRecord method

Get the next Record in the text file and converts in a NotesDocument

Syntax:
Set document = SeqFile.GetNextRecord()
Parameters: nothing
Return value:
The converted document (NotesDocument)
Const IMPORT = 1
Const EXPORT = 2
Const ERRORTitle = "SeqFile Component"

Class SeqFile

' Properties _________________________________________
'#################################################
Private fileNum As Integer
Private fileName As String
Private fieldList As Variant
Private fieldTypeList As Variant
Private fieldSeparator As String
Private delimiterStart As String
Private delimiterStop As String
'#################################################
' ------------------------------------------------------------------

' Methods __________________________________________
'#################################################
Private Sub Extract(doc As NotesDocument, bound As Integer, txt As String)
' Extract a field in the text file
' if typeVal = 0 => Text field to import
' = 1 => number field
' = 2 => date field

Dim item As NotesItem
Dim extractField As Variant
Dim newValue As Variant
Dim arrayValues() As Variant
Dim begin As Integer
Dim numtot As Integer
Dim lenStart As Integer
Dim lenStop As Integer
Dim lenField As Integer
Dim max As Integer
Dim i As Integer

extractField = LeftExt(txt, Me.fieldSeparator)
lenField = Len( extractField )
lenStart = Len( Me.delimiterStart )
lenStop = Len( Me.delimiterStop )

' amputation of the extracted field
begin = lenField + Len( Me.fieldSeparator ) + 1
numtot = Len( txt )
txt = Mid$( txt, begin, numtot )

' remove the delimiters
extractField = Mid$( extractField, lenStart + 1, lenField - lenStop -
lenStart )

Select Case fieldTypeList(bound)
Case "0" : newValue = Trim$(extractField)
Case "1" : newValue = Val(extractField)
Case "2" : newValue = Cdat(extractField)
End Select

' Add or create the item's value
Set item = doc.GetFirstItem(fieldList(bound))
If item Is Nothing Then
Call doc.ReplaceItemValue(fieldList(bound), newValue)
Else
max = Ubound(item.Values)
Redim arrayValues (max + 1)
For i = 0 To max
arrayValues(i) = item.Values(i)
Next
arrayValues(max + 1) = newValue
item.Values = arrayValues
End If
End Sub
'
--------------------------------------------------------------------------------
------------------
Public Sub ImportAll(form As String)
' Import all records of a text file as defined in a configuration document.

Dim session As New NotesSession
Dim dbcur As NotesDataBase
Dim newDoc As NotesDocument
Dim i As Integer
Dim record As String

If Ubound(fieldList) <> Ubound(fieldTypeList) Then
Messagebox "Error : The field list has not the same lenght as the field type
list.", 16, ERRORTitle
Exit Sub
End If

Set dbcur = session.CurrentDataBase

' ---- For each record we create a doc
Do Until Eof(Me.filenum)
Line Input #Me.filenum, record ' extract a line in text file

Set newDoc = dbcur.CreateDocument
newDoc.Form = form

'----------------- EXTRACT FIELDS ----------------------------
For i = 0 To Ubound( fieldList )
Call Extract(newdoc, i, record)
Next

Call newDoc.Save(True,False)

Loop
End Sub
'-------------------------------------------------------------------------------
-------
Public Sub ExportAll(docCollection As NotesDocumentCollection)
' Export all records of a text file as defined in a configuration document

Dim session As New NotesSession
Dim dbcur As NotesDataBase
Dim doc As NotesDocument
Dim item As NotesItem
Dim i As Integer
Dim j As Integer
Dim max As Integer
Dim record As String
This was first published in November 2000

Dig deeper on Domino Resources

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