Follow @dporton

JustCode : Copy one context to another

This JustCode scripts shows you how to loop the questions in your MDD and copy one context label to another. This can be useful when you are setting up mdd files with multiple contexts.

' ****************************************
' Designed by : Smarter Dimensions
' Last Updated : 4th July 2009
' Sub to copy the labels from one context to another.
' ****************************************
CopyContextLabels("c:\temp\short_drinks.mdd","Question" , "CATI")

Sub CopyContextLabels(sFile,sFrom,sTo)

    Dim oMDM,oVar,oElement,sLabel

    Set oMDM = CreateObject("MDM.Document")

    oMDM.Open(sFile, , openConstants.oREADWRITE)

    oMDM.Versions.AddNew()

    For Each oVar in oMDM.Variables
        if oVar.IsSystem = False then
            oMDM.Contexts.Current = sFrom
            sLabel = oVar.Label
            oMDM.Contexts.Current = sTo
            oVar.Label = sLabel
            oMDM.Contexts.Current = sFrom

            For each oElement in oVar.Elements.Elements
              oMDM.Contexts.Current = sFrom
              sLabel = oElement.Label
              oMDM.Contexts.Current = sTo
              oElement.Label = sLabel
           Next
        end if
    Next

    oMDM.Save()

End Sub
 

Leave a Comment

%d bloggers like this: