VB.NET need a class property to be a list array - part 2

altariamx2003
altariamx2003 used Ask the Experts™
on
sorry I dont know how to reopen  post

This is related to the post:
VB.NET need a class property to be a list array (http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_27727643.html)

The solution that the expert give me works, but now I have another error:

"you did not controll nullreferenceexception" (sorry for my english)

this is the class with the change suggested for the expert
Public Class Item
    Private _itemno As String
    Public Property ItemNo() As String
        Get
            Return _itemno
        End Get
        Set(ByVal value As String)
            _itemno = value
        End Set
    End Property

   Public Sub New(ByVal ItemNo As String)

    End Sub

End Class


Public Class Accessory
    Private _items As List(Of Item)
    Public Property Items() As List(Of Item)
        Get
            Return _items
        End Get
        Set(ByVal value As List(Of Item))
            _items = value
        End Set
    End Property

    Public Sub New()
        _items = New List(Of Item)
    End Sub

End Class

Public Class MasterItem
    Private _item As Item
    Public Property PrimaryItem() As Item
        Get
            Return _item
        End Get
        Set(ByVal value As Item)
            _item = value
        End Set
    End Property


    Private _accessories As Accessory
    Public Property Accessories() As Accessory
        Get
            Return _accessories
        End Get
        Set(ByVal value As Accessory)
            _accessories = value
        End Set
    End Property
End Class

Open in new window


The problem is that if I remove  the function "Public Sub New(ByVal ItemNo As String) " from the class vb and I tried to use it
example
Show me the following error:
"Too many arguments for Public sub new()"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015
Commented:
If you remove your New function, you will get the error because there will be not method to receive the call to New Item("TESTACC1"). This is the New you are removing.

If you get rid of your function, you will then need to initialize your objects without a parameter:¸

testItem.Accessories.Items.Add(New Item())
How you use a function in a class when you removed the function from that class?

Author

Commented:
I think I need a break

I have been racking my brain trying this all day
hehehehehe

Im trying this because I would like to do a vb class how has several properties with diferents types like strings, doubles, arrays, etc...


Originally I try with arrays as properties in my class but I check and in diferents blogs several programmers says that I would be better I use a list as properties in my class instead of arrays.

That was Im checking how to use list as properties

This is what I have
Class data
    Private dmyarray(,) As Boolean
    Public Property myarray() As Boolean(,)
        Get
            Return dmyarray
        End Get
        Set(ByVal value As Boolean(,))
            dmyarray = value
        End Set
    End Property
End Class

Open in new window

I would like to know how to do the same but with a list
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Most Valuable Expert 2012
Top Expert 2014
Commented:
You have this as a new question now. What would you store in this property? You have many possible collection types that you can use.

Author

Commented:
hi codecruiser

As I say

In the original project for example:
I had several variables and several arrays that allow me to do some operations.

the data saved on this variables and arrays allows to create a graph.

When the work is finished the data is saved in xml files that represent the graphs (this is not a database).

This xml files the user can move it to others computers with the same program  recreate the graphs or make a new ones.

------------------------------------------------------------------------------------------------------------------------------
In the new version the idea is that in a main project I have a treeview, and when I add a new branch I need to use the same variables and arrays.

but what happend if I add a new branch????, thats way I create a class with several properties that represents the variables and the arrays.

right now Im using arrays in my properties and they works great, but checking in several blogs many programmers says that it is not the best idea if that I use arrays that it would be better if I use a bidimensional list as a properties in my class

best regards
Most Valuable Expert 2012
Top Expert 2014

Commented:
Without looking at all your code, I think DataTables may be more suitable for you given that you have graphs(data points) and XML involved.

Author

Commented:
datatable it is not a option beacause every the program not need a database.

My program create xml files as excel create xls files or word create doc files.
Top Expert 2015
Commented:
You do not need a database to use a DataTable:

Dim yourTable As New DataTable

yourTable.ReadXml("yourXMLFile.xml")
    'Work
yourTable.WriteXml("yourXMLFile.xml")

Author

Commented:
ok thanks thats a great idea, im gonna use it in this project

but it is not what I mean for this issue

I think that I need to explain my self a little better

this is an example of my class
Public Class data
    Private dmyarray1(,) As String
    Public Property myarray1() As String(,)
        Get
            Return dmyarray1
        End Get
        Set(ByVal value As String(,))
            dmyarray1 = value
        End Set
    End Property

    Private dmyname As String
    Public Property myname() As String
        Get
            Return dmyname
        End Get
        Set(ByVal value As String)
            dmyname = value
        End Set
    End Property

    Private dmydouble As Double
    Public Property mydouble() As Double
        Get
            Return dmydouble
        End Get
        Set(ByVal value As Double)
            dmydouble = value
        End Set
    End Property
End Class

Open in new window

when the program starts the user has a default branch in the treeview where he can prepare graphs and solve math algorithms

when the user introduce data in the branch I use the following code
        Dim newtest As new data
        newtest.myname = "Carlos" & str(indexbranch)
        newtest.myarray1(0, 0) = "4.5"
        newtest.mydouble = 4.5

       mydictionary.add(newtest.myname,newtest)

Open in new window


if the user wants, he can add a new branch where he can prepare another graphs and solve another math algorithms, at this point the program needs to use the same variables and arrays but using other values.

Because the user can work with both branch at same time thats way I create a custom class with that can handle all this variables and arrays.

When the user finished if he wants he can save their work, at this point I use xml file to save the information storage in my class.

At this point the class and the dictionary works great and without a problem.

But searching options on internet to improve my code, I read that Many programmers in diferents blogs says  that it is better to use list instead of arrays

Thats way Im tring to explore the optio to use generic list as properties in my class instead of arrays as properties in my class
Most Valuable Expert 2012
Top Expert 2014

Commented:
>I read that Many programmers in diferents blogs says  that it is better to use list instead of arrays

That does not just apply to everyone. Arrays exist for a reason. If arrays are doing the job for you and you do not have any issues then I think you do not need to convert to lists.

Author

Commented:
ok

I thing youre right

I would have liked to know how to do it, but I need to continue

thanks anyway

Author

Commented:
thanks a lot for your time

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial