Tip

Import Delimited File

I have had several needs to run agents a night that pull in delimited files
line by line creating new documents.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
' Dim recList List As cdmsRec
' Dim tempRec As cdmsRec
Dim linestr As String
Dim linearray () As String
Dim vararray (1 To 6) As String 'The array should be dimensioned to have
as many elements as there are separate fields on each record you're
importing
Set db = session.CurrentDatabase

Dim collection As NotesDocumentCollection
Set collection = db.AllDocuments
If Not (db.IsFTIndexed) Then
Call db.UpdateFTIndex(True)
End If
Call collection.FTSearch("phone", 0)
If collection.Count <> 0 Then
Call collection.RemoveAll(True)
End If

filenum% = Freefile () ' Find the first free file number available
Open "C:\phones.txt" For Input As filenum% ' Open the file to be imported,
identifying it with the file number found above
recNum% = 1 ' For each line of the file, read that line into an array
element of linearray
Do While Not Eof (filenum%)
Redim Preserve linearray (recnum%)
Line Input #fileNum%, linestr
linearray (recNum%) = "% " + linestr + "%"
recNum% = recNum% + 1
Loop
Close #fileNum%


For y = 1 To Ubound(linearray) ' This will loop through each element of
linearray, which is each record in the original file
' For each record, parse the individual fields out into an array.
Since there are 38 fields in the file, loop through 38 times
position1% = 1
For x = 1 To 6
'position1% is the position of the first tilde and position2% is the second
tilde. What's between is a field value
position2% = Instr(position1% + 1, linearray(y),
"%")
vararray (x) = Mid$ (linearray (y), position1% + 1, (position2%
- position1%) - 1)
position1% = position2%
Next
Set doc = New NotesDocument (db) ' Create a new document, setting
each field to an element of the vararray
doc.Form = "phone"
doc.LName = vararray (1)
doc.FName = vararray (2)
doc.Ext = vararray (3)
doc.Loc = vararray (4)
doc.DeptNum = vararray (5)
doc.Dept = vararray (6)
doc.ImportFlag = "Import"
Call doc.Save (True, True)
Next

Call db.UpdateFTIndex(True)
End Sub

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.