Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-22
7
Medium Priority
?
225 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
6 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

782 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