Skip to main content

Key Value Extraction Array

Well I just learned something tonight.  The IDEAScript for a key value extraction uses an array to hold all the values to extract.  When I was creating the script I assumed that the array was one of string since it was holding text but when I did that the script kept giving me an error when I got to that line.  Turns out that when you define the array you either don't tell IDEA what it is or define it as a Variant so it needs to be one of these:

Dim myArray(0,0) or Dim myArray(0,0) as Varient - if you define it as string it will give you an error.  The code per the language browser is correct, they just don't give any explanation for what type the array is.

Sub Main

    ' Open the database
    Set db = Client.OpenDatabase("Sample-Customers.IMD")
    
    ' Create the task.
    Set task = db.KeyValueExtraction
    
    ' Define an array to specify the country names.
    Dim myArray(1,0)
    myArray(0,0) = "ARGENTINA"
    myArray(1,0) = "SOUTH AFRICA"
    
    ' Configure the task.
    task.IncludeAllFields
    task.AddKey "COUNTRY", "A"
    task.DBPrefix = "KeyVal"
    task.CreateMultipleDatabases = True
    task.ValuesToExtract myArray
    
    ' Perform the task and output the resulting database name.
    task.PerformTask
    dbName = task.DBName
    
    ' Clear the memory.
    Set task = Nothing
    Set db = Nothing
    
    ' Open the result.
    Client.OpenDatabase(dbName)

End Sub


rachel.organist Wed, 10/14/2020 - 15:14

Also- thanks so much for this tip on the array type! I was driving myself to madness getting the "Invalid procedure call or argument" error repeatedly when I KNEW I was passing a string array...

Brian Element Thu, 10/15/2020 - 14:20

In reply to by rachel.organist

The main problem is that array has to be a multidimensional array, your array is a single array. Also you can't redefine that type of array, you have to set it up at the beginning, so what usually do is define it at its maximum
dim summFieldArray(499,0) as variant
You would populate it with your array values so
summFieldArray(0,0) = "First Key"
summFieldArray(1,0) = "Second Key"
summFieldArray(2,0) = "Third Key"

and so on. Don't worry about the blanks, IDEA seems to ignore those.

Try this out and let me know how it goes.