Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Public
- Option Declare
- Dim explodedText() As String
- Sub Initialize
- '// Init Variables
- Dim s As New notessession
- Dim db As notesdatabase
- Set db = s.currentdatabase
- Dim rowCount As Long
- '// Where is the file?
- Dim filePath As String
- filePath = "c:\temp\owner.csv"
- '// What form to use
- Dim formName As String
- formName = "Default"
- '// Get the file hook, loop through file
- rowCount = 1
- Dim fileNum As Integer
- fileNum = Freefile()
- Open filePath For Input As fileNum
- Dim iLine As String
- Do Until Eof(fileNum)
- Line Input #fileNum, iLine
- Print iLine
- If rowCount = 1 Then
- '// Title
- Dim titleArray As Variant
- titleArray = GetRowArray(iLine)
- Else
- Dim valueArray As Variant
- valueArray = GetRowArray(iLine)
- If Ubound(valueArray) <> Ubound(titleArray) Then
- '// don't do this one
- Print "Error: " & iLine
- Else
- Dim newDoc As notesdocument
- Set newDoc = db.createdocument
- newDoc.Form = formName
- Dim J As Integer
- For J = 0 To Ubound(titleArray)
- Print titleArray(J) & " = " & valueArray(J)
- Call newDoc.replaceitemvalue(ClearQuotes(titleArray(J)),ClearQuotes(valueArray(J)))
- Next
- Call newDoc.save(True,True)
- End If
- End If
- rowCount = rowCount + 1
- Loop
- Close fileNum
- End Sub
- Function explode (Byval inString As String, OutList() As String, delim As String)
- Dim idx As Integer
- Dim begin As Integer
- Dim i As Integer
- i = 0
- begin = 1
- If Right$ ( inString , Len(delim) ) = delim Then
- inString = Left$(inString,Len(inString) - Len(delim))
- End If
- idx = Instr (begin , inString , delim)
- Do While idx > 0
- Redim Preserve outList(0 To i) As String
- outList(i) = Mid$ ( inString , begin , idx - begin )
- i = i + 1
- begin = idx + Len(delim)
- idx = Instr (begin , inString , delim)
- Loop
- Redim Preserve outList(0 To i) As String
- outList(i) = Mid$ ( inString , begin )
- explode = i + 1
- End Function
- Function ClearQuotes(value As String) As String
- Dim newStr As String
- newStr = Strright(value,|"|)
- newStr = Strleftback(newStr,|"|)
- If value = |""| Then
- ClearQuotes = ""
- ElseIf newStr = "" Then
- ClearQuotes = value
- Else
- ClearQuotes = newStr
- End If
- End Function
- Function GetRowArray(iLine As String) As Variant
- Call explode (iLine,explodedText,",")
- GetRowArray = explodedText
- End Function
Add Comment
Please, Sign In to add comment