Guest User

Untitled

a guest
Jan 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. Option Public
  2. Option Declare
  3. Dim explodedText() As String
  4. Sub Initialize
  5.  
  6. '// Init Variables
  7. Dim s As New notessession
  8. Dim db As notesdatabase
  9. Set db = s.currentdatabase
  10. Dim rowCount As Long
  11.  
  12. '// Where is the file?
  13. Dim filePath As String
  14. filePath = "c:\temp\owner.csv"
  15.  
  16. '// What form to use
  17. Dim formName As String
  18. formName = "Default"
  19.  
  20. '// Get the file hook, loop through file
  21. rowCount = 1
  22. Dim fileNum As Integer
  23. fileNum = Freefile()
  24. Open filePath For Input As fileNum
  25. Dim iLine As String
  26. Do Until Eof(fileNum)
  27. Line Input #fileNum, iLine
  28. Print iLine
  29. If rowCount = 1 Then
  30. '// Title
  31. Dim titleArray As Variant
  32. titleArray = GetRowArray(iLine)
  33. Else
  34. Dim valueArray As Variant
  35. valueArray = GetRowArray(iLine)
  36. If Ubound(valueArray) <> Ubound(titleArray) Then
  37. '// don't do this one
  38. Print "Error: " & iLine
  39. Else
  40. Dim newDoc As notesdocument
  41. Set newDoc = db.createdocument
  42. newDoc.Form = formName
  43. Dim J As Integer
  44. For J = 0 To Ubound(titleArray)
  45. Print titleArray(J) & " = " & valueArray(J)
  46. Call newDoc.replaceitemvalue(ClearQuotes(titleArray(J)),ClearQuotes(valueArray(J)))
  47. Next
  48. Call newDoc.save(True,True)
  49. End If
  50. End If
  51. rowCount = rowCount + 1
  52. Loop
  53. Close fileNum
  54.  
  55.  
  56.  
  57.  
  58. End Sub
  59. Function explode (Byval inString As String, OutList() As String, delim As String)
  60. Dim idx As Integer
  61. Dim begin As Integer
  62. Dim i As Integer
  63. i = 0
  64. begin = 1
  65. If Right$ ( inString , Len(delim) ) = delim Then
  66. inString = Left$(inString,Len(inString) - Len(delim))
  67. End If
  68. idx = Instr (begin , inString , delim)
  69. Do While idx > 0
  70. Redim Preserve outList(0 To i) As String
  71. outList(i) = Mid$ ( inString , begin , idx - begin )
  72. i = i + 1
  73. begin = idx + Len(delim)
  74. idx = Instr (begin , inString , delim)
  75. Loop
  76. Redim Preserve outList(0 To i) As String
  77. outList(i) = Mid$ ( inString , begin )
  78. explode = i + 1
  79. End Function
  80. Function ClearQuotes(value As String) As String
  81.  
  82. Dim newStr As String
  83. newStr = Strright(value,|"|)
  84. newStr = Strleftback(newStr,|"|)
  85. If value = |""| Then
  86. ClearQuotes = ""
  87. ElseIf newStr = "" Then
  88. ClearQuotes = value
  89. Else
  90. ClearQuotes = newStr
  91. End If
  92.  
  93. End Function
  94. Function GetRowArray(iLine As String) As Variant
  95.  
  96. Call explode (iLine,explodedText,",")
  97. GetRowArray = explodedText
  98.  
  99. End Function
Add Comment
Please, Sign In to add comment