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.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team
Post Reply
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

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

Post by Tom, Tech Support » Fri Jul 29, 2011 10: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:

wsh-datasource-1.txt:

Code: Select all

[iOpus]
dataset-title=Dataset<SP>No.<SP>1 
dataset-item1=First<SP>Dataset
And the values would be referenced in a macro file as follows:

Code: Select all

SET !DATASOURCE wsh-datasource-1.txt 
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:TestForm ATTR=NAME:Name CONTENT={{dataset-title}}
TAG POS=1 TYPE=TEXTAREA FORM=NAME:TestForm ATTR=NAME:Remarks CONTENT={{dataset-item1}} 
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
PlayLOV.zip
(1.29 KiB) Downloaded 32118 times

Code: Select all

Option Explicit

Const OPEN_FILE_FOR_READING = 1

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"
	WScript.Quit()
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

ReadMacroFile(macroFullPath)

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
		Else
			folderDataSource = GetiMacrosFolder("DataSources")
		End If
		
		If InStr(lovFile, "\") <> 1 Then
			If Right(folderDataSource, 1) = "\" Then
				lovFullPath = folderDataSource & lovFile
			Else
				lovFullPath = folderDataSource & "\" & lovFile
			End If
		End If
	End If
	
	ReadLOVFile(lovFullPath)		

End If

CheckErr(im.iimPlay(macroFullPath))

Sub ReadMacroFile(macroFullPath)

	Const POS_VARIABLE_VALUE = 2

	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"
		WScript.Quit()
	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
		
	Loop
	
	macroFile.Close

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"
		WScript.Quit()
	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
		
	Loop
	
	lovFile.Close

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
		WScript.Quit()
	End If
	
End Sub
Regards,

Tom, iMacros Support
Post Reply