Link to home
Start Free TrialLog in
Avatar of altariamx2003
altariamx2003Flag for Mexico

asked on

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

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 (https://www.experts-exchange.com/questions/27727643/VB-NET-need-a-class-property-to-be-a-list-array.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
User generated image
Show me the following error:
"Too many arguments for Public sub new()"
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of altariamx2003

ASKER

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
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
>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.
ok

I thing youre right

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

thanks anyway
thanks a lot for your time