Reading unlimited columns of CSV file with Scripting Edition

Information related to the use of iMacros for form filling and data upload.

Moderator: iMacros Moderators

Reading unlimited columns of CSV file with Scripting Edition

by Hannes, Tech Support on Mon Nov 06, 2006 6:37 am

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 Mon Sep 14, 2009 10:50 pm, edited 1 time in total.
Reason: changed CreateObject() call to "imacros"
Hannes, iOpus Support
Hannes, Tech Support
Posts: 2120
Joined: Thu Sep 21, 2006 6:27 am

Return to How-To's and Examples for Form Filling

Who is online

Users browsing this forum: No registered users and 2 guests