Solved

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

Posted on 2014-09-22
7
194 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
Comment Utility
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
Comment Utility
Make the  line as:

Me.providerField = New MF.Provider()
0
 

Author Comment

by:macyp
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:macyp
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. That solved the error.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Framework versus framework 64 in IIS 8.5 5 78
Paging GridView 7 32
Closing all open child forms. 4 22
Achieve json result 2 28
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now