Solved

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

Posted on 2014-09-22
7
198 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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