How to use a List of Variables file with iMacros 7 and later

Share your tips, tricks and favorite iMacros macros, scripts and applications for web automation in general here.

Moderator: iMacros Moderators

How to use a List of Variables file with iMacros 7 and later

by Tom, Tech Support on Fri Jul 29, 2011 3:36 am

Versions of iMacros prior to V7 supported a special input file type known as a List of Variables (LOV) file. Here is an example:

Code: Select all

And the values would be referenced in a macro file as follows:

Code: Select all
SET !DATASOURCE wsh-datasource-1.txt

Unfortunately, input from a LOV file is no longer supported. However, if you have the scripting edition, you can use the following VBScript to run your macros and it will automatically read the old-style LOV file and set the appropriate values in the macro for you.

To use the script, specify the name of the macro you want to run as the first argument on the command line for the script:

Code: Select all
C:\MyScripts\PlayLOV.vbs MyMacro
(1.29 KIB) Downloaded 31118 times

Code: Select all
Option Explicit


Dim g_folderDataSource
Dim g_dataSource

Dim args
Set args = WScript.Arguments

If args.Count = 0 Then
   MsgBox "Macro file must be specified as the first argument to the script:" & vbNewLine & vbNewLine &_
   WScript.ScriptName & " macro", vbCritical, WScript.ScriptName & " Error"
End If

Dim macro, macroFullPath

macro = args(0)

If InStr(macro, ".iim") = 0 Then
   macro = macro & ".iim"
End If

macroFullPath = macro

If InStr(macro, ":") = 0 Then
   Dim folderMacros
   folderMacros = GetiMacrosFolder("Macros")
   If InStr(macro, "\") <> 1 Then
      macroFullPath = folderMacros & "\" & macro
   End If
End If


Dim im
Set im = CreateObject("iMacros")

CheckErr(im.iimInit(, False))

If Len(g_dataSource) > 0 Then

   Dim lovFile, lovFullPath
   lovFile = g_dataSource
   lovFullPath = lovFile
   If InStr(lovFile, ":") = 0 Then
      Dim folderDataSource
      If Len(g_folderDataSource) > 0 Then
         folderDataSource = g_folderDataSource
         folderDataSource = GetiMacrosFolder("DataSources")
      End If
      If InStr(lovFile, "\") <> 1 Then
         If Right(folderDataSource, 1) = "\" Then
            lovFullPath = folderDataSource & lovFile
            lovFullPath = folderDataSource & "\" & lovFile
         End If
      End If
   End If

End If


Sub ReadMacroFile(macroFullPath)


   Dim fso, macroFile, inputLine
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set macroFile = Nothing
   On Error Resume Next
   Set macroFile = fso.OpenTextFile(macroFullPath,  OPEN_FILE_FOR_READING)
   On Error Goto 0
   If macroFile Is Nothing Then
      MsgBox "Could not open macro file " & macroFullPath, vbCritical, WScript.ScriptName & " Error"
   End If
   Do While macroFile.AtEndOfStream <> True

      inputLine = UCase(Trim(macroFile.ReadLine))

      If Len(inputLine) > 0 And Left(inputLine, 1) <> "'" Then
         Dim SplitArray
         If InStr(inputLine, "!FOLDER_DATASOURCE") > 0 Then
            SplitArray = Split(inputLine, " ")
            g_folderDataSource = Replace(SplitArray(POS_VARIABLE_VALUE), "<SP>", " ")
         ElseIf InStr(inputLine, "!DATASOURCE") > 0 Then
            SplitArray = Split(inputLine, " ")
            If SplitArray(1) = "!DATASOURCE" Then
               g_dataSource = Replace(SplitArray(POS_VARIABLE_VALUE), "<SP>", " ")
            End If
         End If
      End If

End Sub

Sub ReadLOVFile(lovFullPath)

   Dim fso, lovFile, inputLine, splitPos, key, value
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set lovFile = Nothing
   On Error Resume Next
   Set lovFile = fso.OpenTextFile(lovFullPath, OPEN_FILE_FOR_READING)
   On Error Goto 0

   If lovFile Is Nothing Then
      MsgBox "Could not open input file " & lovFullPath, vbCritical, WScript.ScriptName & " Error"
   End If
   Do While lovFile.AtEndOfStream <> True

      inputLine = Trim(lovFile.ReadLine)

      If Len(inputLine) > 0 And Left(inputLine, 1) <> "'" Then
         splitPos = InStr(2, inputLine, "=")

         If splitPos > 0 Then
            key = Trim(Left(inputLine, splitPos - 1))
            value = Trim(Right(inputLine, Len(inputLine) - splitPos))

            CheckErr(im.iimSet(key, value))
         End If
      End If

End Sub

Function GetiMacrosFolder(folderName)
   ' Valid values for folderName are: Macros, DataSources, Downloads, and Logs.
   Dim WshShell
   Set WshShell = CreateObject("WScript.Shell")
   GetiMacrosFolder = WshShell.RegRead("HKEY_CURRENT_USER\Software\iOpus\iMacros\Folder" & folderName)
End Function

Sub CheckErr(retCode)

   If retCode < 0 Then
      MsgBox im.iimGetLastError(), vbCritical, "Macro Error: " & retCode
   End If
End Sub

Tom, iMacros Support
Tom, Tech Support
Posts: 3300
Joined: Mon May 31, 2010 9:59 am

Return to How-To's and useful iMacros: All other topics

Who is online

Users browsing this forum: No registered users and 3 guests