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 Data As Variant
Open "d:\contact.txt" For Input As fileNum%
Do Until Eof(1)
Line Input #1, text$
' ระบุตัวคั่นของแต่ละฟิลด์แล้วแปลงเป็น array ไว้ในตัวแปรชื่อ Data
Data = Split(Cstr(text$),";")
Set Doc = Db.CreateDocument
Set Item = Doc.ReplaceItemValue("Code",Data(0))
Set Item = Doc.ReplaceItemValue("Title",Data(1))
Set Item = Doc.ReplaceItemValue("FirstName",Data(2))
Set Item = Doc.ReplaceItemValue("LastName",Data(3))
Set Item = Doc.ReplaceItemValue("Address",Data(4))
Set Item = Doc.ReplaceItemValue("Address2",Data(5))
Set Item = Doc.ReplaceItemValue("OfficePhone",Data(6))
Set Item = Doc.ReplaceItemValue("Form","Contact")
Call Doc.save (True, True)
Loop
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 ***
z_strRemaining = strSource
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), _
Len(z_strRemaining))
Else
z_intItemCount = z_intItemCount + 1
z_strRemaining = ""
End If
Wend
' 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 individual array elements:
While (Not z_strRemaining = "")
For intElement = 0 To Ubound(astrReturn)
' Find the end of the current element:
z_intEndOfItem = Instr(1, z_strRemaining, strItemDelim)
' If there is still an item delimiter in the string, parse
' out the item, otherwise assume the remaining text is the
' last item:
If (z_intEndOfItem <> 0) Then
z_strCurItem = Mid(z_strRemaining, 1, z_intEndOfItem - 1)
astrReturn(intElement) = z_strCurItem
z_strRemaining = Mid(z_strRemaining, z_intEndOfItem + Len(strItemDelim), _
Len(z_strRemaining))
Else
astrReturn(intElement) = z_strRemaining
z_strRemaining = ""
End If
Next
Wend
' Return the split array to the caller:
split = astrReturn
End Function
:yellow_cool.gif: |