Trouble filling an xml schema array class from excel data with a macro

  • 13 years ago

    Hi to anyone who can help me,

    I've only been a developer for a few days so pls try to keep it simple.

    The story so far: I have started with an xml schema. I have converted this schema into vb classes using xsd.exe. I have made these classes into Com classes and created a .tlb which I am using with Excel's visual basic editor. I am now running into trouble attempting to write an xml where one of the classes is an array of enumerations. Let me show you. This is the relevant bits of the class (which itself is a sub-class of a class called 'report')

    Partial Public Class EnergyAssessor

     Private qualificationsField() As AssessorQualificationsCode
             <System.Xml.Serialization.XmlElementAttribute("Qualifications")> _
            Public Property Qualifications() As AssessorQualificationsCode()
                    Return Me.qualificationsField
                End Get
                Set(ByVal value As AssessorQualificationsCode())
                    Me.qualificationsField = value
                End Set
            End Property
    End Class

     This is the enumeration:

    <System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42"), _
         System.SerializableAttribute(), _
         System.Xml.Serialization.XmlTypeAttribute([Namespace]:="DCLG-CEPC")> _
        Public Enum AssessorQualificationsCode





        End Enum

    Referencing this in VB6 I have declared the objects like this:

    Dim thisReport As New report
    Dim thisReportHeader As New ReportHeader
    Dim thisEnergyAssessor As New EnergyAssessor
    Set thisReport.ReportHeader = thisReportHeader
    Set thisReport.ReportHeader.EnergyAssessor = thisEnergyAssessor

     and am able to apply attributes of the class with commands like this:

    thisEnergyAssessor.CompanyName = Cells(14, 6)

     I would have thought that I could then do something like this with the array:

    while not (Cells(1,i) = null)
    thisEnergyAssessor.Qualifications(i) = Cells(1,i)
    i = i + 1

     But I get a compilation error. Similarly to read attributes from an existing class that I have filled from an xml document I have tried

    Dim i As Integer
    i = UBound(thisReport.ReportHeader.EnergyAssessor.Qualifications)
    For j = 0 To i
    Cells(x, i) = thisReport.ReportHeader.EnergyAssessor.Qualifications(i)
    Next j

    but i get a compilation error: Wrong number of arguments or invalid property assignment.

    Is there another way? Cheers. Russ.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Never trust a programmer in a suit.” - Anonymous