Solved

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

Posted on 2014-09-22
7
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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