I am trying to create code to represent a form document using VBA in Word 2007. I have created classes to represent Section, QuestionSet and Question.
So, I have 15 sections. I created a function to create each "Section" object, to add it to the "Section" collection, then destroy the object, as a result, the objects remain constant in the collection (or something else).
Can I use the same method to add collections to collections, or will I need to define each collection explicitly?
Code in the module:
Public Sections As Collection Function DefineSection(ByVal SectionName As String) Set Section = New clsSection Section.myName = SectionName Sections.Add Section, SectionName End Function Function DefineQuestionSet(ByVal SectionName As String, ByVal Name As String, ByVal NoOfQuestions As Integer, ByVal IsMutuallyExclusive As Boolean, Optional ByVal DependentOnSection As String) Dim Qsets As Collection Set Qsets = New Collection Set QuestionSet = New clsQuestionSet QuestionSet.Name = Name QuestionSet.NoOfQuestions = NoOfQuestions QuestionSet.MutuallyExclusive = IsMutuallyExclusive If Not (DependentOnSection) = "" Then QuestionSet.DependentOnSection = DependentOnSection End If Qsets.Add QuestionSet Sections.Item(SectionName).Add Qsets End Function
This is then called through:
Sub Initilise() Set Sections = New Collection DefineSection "PersonalDetails" DefineQuestionSet "PersonalDetails", "PersonalDetails", 29, False End Sub
Stevo
source share