1: ' Created by Forgetdata Limited. 2009
2: ' Website: http://www.forgetdata.com
3: ' Description:
4: ' CombineVariables generates a new metadata variable based on each combination of categories of 2 other variables
5: '
6: ' Parameters:
7: ' oMDMFields: the MDM Fields Collection where the variables you want to combine are located
8: ' var1: The name (its a string) of the first variable you want to combine
9: ' var2: The name (also a string) of the second variable you want to combine
10: ' oMDM: The owner MDM Document which is needed so that the function can call CreateVariable
11: Function CombineVariables(oMDMFields, var1, var2, oMDM)
12:
13: Dim fldVar1, fldVar2, combVar,newVarName
14: set fldVar1 = oMDMFields[var1]
15: set fldVar2 = oMDMFields[var2]
16:
17: newVarName = var1 + "___" + var2
18:
19: if (NOT oMDMFields.Exist[newVarName] ) Then
20: Set combVar = oMDM.CreateVariable(newVarName, fldVar1.Label + " - " + fldVar2.Label)
21: else
22: Debug.Log("Combine variable "+ newVarName + "already exists, not creating") 23: Exit Function
24: end if
25:
26: combVar.HasCaseData = false
27:
28: const mtCategorical = &H0003
29: const sExpressions = &H0004
30: const mtCategory = &H0000
31: combVar.DataType = mtCategorical
32: combVar.SourceType = sExpressions
33:
34:
35: Dim elem1,elem2,combElem
36: for each elem1 in fldVar1.Elements
37: for each elem2 in fldVar2.Elements
38: set combElem = combVar.Elements.AddNewElement(elem1.Name +"_"+elem2.Name, mtCategory)
39: combElem.Expression = var1 + ".ContainsAny({" + elem1.Name + "}) AND " + var2 + ".ContainsAny({" + elem2.Name + "})" 40: combElem.Label = elem1.Label + " - " + elem2.Label
41: next
42: next
43: oMDMFields.Add(combVar)
44: CombineVariables = combVar
45:
46: End Function