Forum Moderators: open
I have a set of CSV from a form in roughly the following format:
Name1,email1,title1
Name2,email2,title2
Name3,email3,title3
….n
I would like to read these into variables, rather like and array in php then loop through them and send a mail to each. Any pointers would be greatly appreciated, I ripped some hair out yesterday. :)
Cheers
From there it should be simple enough to remove my demo code and add your email component code into the loop...
<%
Option Explicit'Code to display data from the current text-based logfile
Dim objFSO, oInStream, sLine, sSeg'Define the constants used by the FSO
Const ForReading = 1'Create an instance of the FSO
Set objFSO = CreateObject("Scripting.FileSystemObject")'Check the file exists
If objFSO.FileExists( Server.MapPath( "stuff.txt" ) ) Then'Open a file for reading
Set oInStream = objFSO.OpenTextFile( Server.MapPath( "stuff.txt" ), ForReading, False )Do Until oInStream.AtEndOfStream
sLine = oInStream.ReadLine
sSeg = Split( sLine, "," )Response.Write "<b>A</b>: " & sSeg(0)
Response.Write "<b>B</b>: " & sSeg(1)
Response.Write "<b>C</b>: " & sSeg(2)
Response.Write "<br>"Loop
oInStream.Close
Set oInStream = NothingElse
Response.Write "File not found!"
End If
Set objFSO = Nothing
%>
- Tony
Still having difficulties, I tried variations of your code but to no avail. I have managed to get a little bit closer to my aim by getting all the values from the string which are separated into an array and print them out to the page.
I still cant figure how to get them into 3 different arrays.
Here is a snippet of how far I have got.
Cheers.
dim strData, strOneWord, array
strData = Request.Form("data_input")
strData = replace(strData,vbCRLF,",")
array = split(strData , ",", -1 , 1)
For Each strOneWord in array
response.write(strOneWord)
response.write("<br>")
Next
strData = Request.Form("data_input")
'replace new line with a comma
strData = replace(strData,vbCRLF,",")
arrayData = split(strData , ",", -1 , 1)
count = UBound(arrayData)
iterations = ((count + 1) / 3)
for i=0 to (iterations - 1)
email = arrayData((i * 3))
name = arrayData(((i * 3) +1))
url = arrayData(((i * 3)+2))
'write to page to prove it works or do your function
response.write(email) & " " & (name) & " " & (url) & "<hr>"
next
Multi-dimensional arrays are available if you need to use them. You can build a static one like this;
Dim sArray(0 to 10, 0 to 10)
Or you can make a dynamic array which can be resized (well within limits, you can change the last dimension but no others).
Very quick example of expanding an array;
'Create & initialise
Dim sArray()
ReDim sArray(0 to 3,0)sArray(0 to 3,0) = ""
...
Do Until Data.EOF
'Note the preserve, this retains data after the resize
If sArray(0,UBound( sArray, 2 )) <> "" Then
'No more empty variables, expand the array
ReDim Preserve sArray(0 to 3, LBound( sArray, 2 ) To UBound( sArray, 2 )+1)
End IfsArray(0,UBound( sArray, 2 )) = Data("Field1").Value
sArray(1,UBound( sArray, 2 )) = Data("Field2").Value
sArray(2,UBound( sArray, 2 )) = Data("Field3").Value
sArray(3,UBound( sArray, 2 )) = Data("Field4").ValueData.NextRec
Loop...
- Tony