| Option Explicit
MsgBox "This script demonstrates how to read data from a simple text file and submit this information to a website. It reads from the file <IIM-TEST-SUBMIT.CSV> file and uses the macro <wsh-submit-2-web.iim>." + vbCrLf + VbCrLf + "Tip: This script has the same function as <database-2-web.vbs> script but uses a text file instead of a database as input." + vbCrLf + VbCrLf + "Note: If you change the file name of the input text file, you also need to change it in the <schema.ini> file."
'Tip: For more information on the method used here
'search for "Text File Driver" and "Schema.ini" in any search engine
'Note: On some language versions of Windows (e.g. German (Deutsch)) CSV data is separated by semicolons (;)
'and not a comma (,). This this case you need to replace all "," by ";" in the input file ("iimsubmit.csv")
Dim rs, sDir, strConnect
Dim iim1, iret
set rs = createobject("ador.recordset")
sDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 'Get current directory
strConnect = _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"DefaultDir=" & sDir & ";"
Const adOpenStatic = 3
rs.open "select * from iimsubmit.csv", strConnect, adOpenStatic
MsgBox "Input file information:" & vbCrLf & vbCrLf & _
"Recordcount: " & rs.recordcount & vbCrLf & vbCrLf & _
"Fields per record: " & rs.fields.count
set iim1= CreateObject ("InternetMacros.iim")
iret = iim1.iimInit
iret = iim1.iimDisplay("Submitting Data")
do until rs.eof
'Set the variables
iret = iim1.iimSet("-var_FNAME", rs.fields(0))
iret = iim1.iimSet("-var_LNAME", rs.fields(1))
iret = iim1.iimSet("-var_ADDRESS", rs.fields(2))
iret = iim1.iimSet("-var_CITY", rs.fields(3))
iret = iim1.iimSet("-var_ZIP", rs.fields(4))
iret = iim1.iimSet("-var_STATE-ID", rs.fields(5))
iret = iim1.iimSet("-var_COUNTRY-ID", rs.fields(6))
iret = iim1.iimSet("-var_EMAIL", rs.fields(7))
'Run the macro
'Same macro as in database-2-web.vbs example!!!
iret = iim1.iimPlay("wsh-submit-2-web")
If iret < 0 Then
MsgBox iim1.iimGetLastError()
End If
rs.movenext
loop
iret = iim1.iimDisplay("Done!")
iret = iim1.iimExit
WScript.Quit(0)
|