' Define function and its parameters Function GetQuestionLevels(currLevel As Question, Levels As QuestionArray, ParentLevels As QuestionArray) As Number Dim parentQuestion = currLevel.Parent ' find the parent question of the 1st parameter (store in parentQuestion) If parentQuestion.Shortcut <> "" Then ' if there is no parent question i.e. you are on the highest/outermost loop... Dim parentLevel = Levels.FindByShortcut(parentQuestion.Shortcut) ' it is the parent level (store in parentlevel) If parentLevel.Shortcut <> "" Then ParentLevels.Push(parentQuestion) ' store all parentLevels in an array Endif return GetQuestionLevels(parentQuestion, Levels, ParentLevels) Endif End Function ' Create portfolio Dim resPortfolio As Portfolio Dim nQuestion For nQuestion = 1 to Survey.Questions.Count Dim currQuestion = Survey.Questions[nQuestion] If (currQuestion.Type = "single" or currQuestion.Type = "multiple") And Not(currQuestion.IsDeveloped) Then ' we're only interested in child questions which are multi, single and also non-developed questions If Survey.Levels.FindByShortcut(currQuestion.Shortcut).Shortcut = "" Then ' if the current question is not a level Dim ParentLevels As QuestionArray ' push its parent levels into the array, ParentLevels, using the function GetQuestionLevels(currQuestion, Survey.Levels, ParentLevels) Dim resItem As PortfolioItem ' Create a tab definition for every level question resItem.SetType(1) resItem.SetTitle(currQuestion.Shortcut) resItem.TabDef.ReadTabTemplate("Askia Simple") resItem.TabDef.Rows.Add(currQuestion) ' Add the child question to the rows If ParentLevels.Count >= 1 Then resItem.TabDef.Columns.Add(ParentLevels[1]) ' Add the 1st parent loop question to the columns If ParentLevels.Count >= 2 Then resItem.TabDef.Edges.Add(ParentLevels[2]) ' Add the 2nd parent loop question to the Edges If ParentLevels.Count >= 3 Then Dim i For i = 3 To ParentLevels.Count ' Add all further parent loop questions to the edges (N.B. the tab template has 'Netsed edges' ticked) resItem.TabDef.Edges.Add(ParentLevels[i]) Next i EndIf EndIf resPortfolio.Add(resItem) EndIf Endif EndIf Next nQuestion resPortfolio.Save(Survey.Directory + "11. Loop Summary Tables.xml") resPortfolio.Open()