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
 

JustCode : Sub to change the label on a specified question.

This JustCode script shows us how to find a question and changes its label to a new string.

' ****************************************
' Designed by : Smarter Dimensions
' Last Updated : 5th July 2009
' Sub to change the label on a specified question.
' ****************************************

ChangeQuestionText("c:\temp\short_drinks.mdd","Question","gender","NewText")

Sub ChangeQuestionText(sFile,sContext,sQuestion,sText)

Dim oMDM

Set oMDM = CreateObject("MDM.Document")

oMDM.Open(sFile, , 2)

oMDM.Contexts.Current = sContext

oMDM.Variables[sQuestion].Label = sText

oMDM.Save(sFile)

Set oMDM = null
End Sub
%d bloggers like this: