Textfile Import (With Delimiter)

Import Text-Files with delimiter
Dim DB As NotesDatabase
Dim Doc As NotesDocument
Dim Item As NotesItem

Sub Click(Source As Button)
Dim s As New NotesSession
Set Db = s.CurrentDatabase

' Open a file, print it, and close the file.
Dim text As String, fileNum As Integer
fileNum% = Freefile()
Dim Daten As Variant
Open "d:\daten.txt" For Input As fileNum%
Do Until Eof(1)
Line Input #1, text$

' String in Einzelwerte splitten
Daten = Split(Cstr(text$),";")
'Msgbox Daten(3)
Set Doc = Db.CreateDocument

Set Item = Doc.ReplaceItemValue("BKR",Daten(0))
Set Item = Doc.ReplaceItemValue("Werk",Daten(1))
Set Item = Doc.ReplaceItemValue("ArtikelNr",Daten(2))
Set Item = Doc.ReplaceItemValue("ArtikelBez",Daten(3))
Set Item = Doc.ReplaceItemValue("Basismenge",Daten(4))
Set Item = Doc.ReplaceItemValue("Basismengeneinheit",Daten(5))
Set Item = Doc.ReplaceItemValue("KopfG?ltigVon",Daten(6))
Set Item = Doc.ReplaceItemValue("KopfG?ltigBis",Daten(7))
Set Item = Doc.ReplaceItemValue("Komponente",Daten(8))
Set Item = Doc.ReplaceItemValue("Komponentenbezeichnung",Daten(9))
Set Item = Doc.ReplaceItemValue("Einsatzmenge",Daten(10))
Set Item = Doc.ReplaceItemValue("Einsatzmengeneinheit",Daten(11))
Set Item = Doc.ReplaceItemValue("KompG?ltigVon",Daten(12))
Set Item = Doc.ReplaceItemValue("KompG?ltigBis",Daten(13))
Set Item = Doc.ReplaceItemValue("Form","Komponente")

Call Doc.save (True, True)
Close fileNum%
End Sub

Function split(strSource As String, strItemDelim As String) As Variant

Dim astrReturn() As String ' The array to return

Dim intElement As Integer ' The array element currently being set
Dim z_intItemCount As Integer ' The total number of elements for the array
Dim z_intStartOfItem As Integer ' The start position of the item in the
' source string.
Dim z_intEndOfItem As Integer ' The end position of the item in the source
' string.

Dim z_strCurItem As String ' The currently parsed item
Dim z_strRemaining As String ' The remaining string to cycle through
Dim z_strStartOfItemBack As String ' The rest of the string, from the
start of
' the item on back.
'*** End Variable
Declarations ***

' Put the source string
into a holder:
z_strRemaining = strSource

' Cycle through the
source string and get a
' count of elements:
While (Not z_strRemaining = "")
z_intStartOfItem = Instr(1, z_strRemaining, strItemDelim)

If (z_intStartOfItem <> 0) Then
z_intItemCount = z_intItemCount + 1
z_strRemaining = Mid(z_strRemaining, z_intStartOfItem +
Len(strItemDelim), _
z_intItemCount = z_intItemCount + 1
z_strRemaining = ""
End If

' Size the return array
so that it can hold
' all of the elements:
Redim astrReturn(z_intItemCount - 1)

' Reset the holder to
the value of the source string:
z_strRemaining = strSource

' Cycle through the
source list, parsing the
' string into

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.