Reading unlimited columns of CSV file with Scripting Edition

Information related to the use of iMacros for form filling and data upload.
Post Reply
Hannes, Tech Support

Reading unlimited columns of CSV file with Scripting Edition

Post by Hannes, Tech Support » Mon Nov 06, 2006 1:37 pm

Loop through the lines of a CSV file, and put all entries of one line into an array:

Code: Select all

Option Explicit

'global variables: use for customization
INPUT_PATH = "C:\Programme\iMacros\datasources\myfile.csv" 'CSV format expected
'initialize macro and related variables
dim iret,iim1,index,initMacro
set iim1 = CreateObject ("imacros")
iret = iim1.iimInit()

' setting up file access
Dim objFileSystem, objInputFile, inputFile, inputFileStream
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set inputFile = objFileSystem.GetFile(INPUT_PATH)
Const ForReading = 1 ' means: open for reading
Const TristateDefault = -2 ' means: read as ASCII
Set inputFileStream = inputFile.OpenAsTextStream(ForReading, TristateDefault)

'main loop through all lines in inputFile
Dim aktInputLine, entries

do until (inputFileStream.atEndOfStream)

   'read next line from input file
   aktInputLine = inputFileStream.ReadLine
   'put CSV-data into entries array.
   entries = Split(aktInputLine, ",")
   ' now, entries(0), entries(1), etc contain the actual line's data
   ' and may be used in the script, or - with iimSet() - in a macro.
More examples of reading files and using their content in macros via the scripting interface can be found in iMacros' examples folder: "file-2-web.vbs" and "file--2-web-method2.vbs".
Last edited by Hannes, Tech Support on Tue Sep 15, 2009 5:50 am, edited 1 time in total.
Reason: changed CreateObject() call to "imacros"
Post Reply