Solved

Value of type ' 'cannot be converted to '1-dimensional array of ' '

Posted on 2014-09-22
7
197 Views
Last Modified: 2014-09-24
I have the following VB.NET Class (Visual Studio version 2010). This class is for serializing XML's.

Public Class PracticeInformation

    Private practiceIdentifierField As PracticeIdentifiers

    Private practiceNameField As String

    Private addressField As AddressInformation

    Private contactField As ContactPersonal

    Private providerField() As Provider


    Public Sub New()
        Me.practiceIdentifierField = New MF.PracticeIdentifiers
        Me.addressField = New MF.AddressInformation
        Me.contactField = New MF.ContactPersonal
'Line where the error happens 
       [b] Me.providerField = New MF.Provider[/b]
    End Sub
    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _
    Public Property PracticeIdentifier() As PracticeIdentifiers
        Get
            Return Me.practiceIdentifierField
        End Get
        Set(value As PracticeIdentifiers)
            Me.practiceIdentifierField = Value
        End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _
    Public Property PracticeName() As String
        Get
            Return Me.practiceNameField
        End Get
        Set(value As String)
            Me.practiceNameField = Value
        End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _
    Public Property Address() As AddressInformation
        Get
            Return Me.addressField
        End Get
        Set(value As AddressInformation)
            Me.addressField = Value
        End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _
    Public Property Contact() As ContactPersonal
        Get
            Return Me.contactField
        End Get
        Set(value As ContactPersonal)
            Me.contactField = Value
        End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute("Provider", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)> _
    Public Property Provider() As Provider()
        Get
            Return Me.providerField
        End Get
        Set(value As Provider())
            Me.providerField = Value
        End Set
    End Property
End Class

Open in new window


In the Subroutine New(), I get an error on line 4:
Me.providerfield = new MF.Provider
The error says: "Value of type MF.Provider' cannot be converted to '1 dimensional array of MF.Provider'.
How can I fix this error?
0
Comment
Question by:macyp
  • 3
  • 2
7 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40338025
You have declared

Private providerField() As Provider

which is an array

If you want it to be just a single object then remove the ()

Private providerField As Provider
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40338442
Make the  line as:

Me.providerField = New MF.Provider()
0
 

Author Comment

by:macyp
ID: 40339067
ChloesDad, I want Provider to be an array.

Ramkisan jagtap, I tried
Me.Providerfield = New MF.Provider() and it still gives me the same error on that line.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:macyp
ID: 40339600
Anyone, any suggestions?
 I really need to fix this error to go forward with my project.
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40339972
You cant do what you want to do in 1 line.

You would have to do

Dim NumberOfElements as Integer = yournumber
Private providerField(NumberOfElements) As Provider

For Count1 = 0 to NumberOfElements -1
  Me.providerField(Count1) = New MF.Provider
NExt Count1

Of course this only works if you know how many elements that you need in the first place.

If you don't then its better to use a collection as you can add new items to a collection as you need to.
0
 

Author Comment

by:macyp
ID: 40342720
Thanks. That solved the error.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question