Avatar of altariamx2003
altariamx2003
Flag 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/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()"
Visual Basic.NET

Avatar of undefined
Last Comment
altariamx2003

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jacques Bourgeois (James Burger)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
adriankohws

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
altariamx2003

ASKER
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
Nasir Razzaq

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
altariamx2003

ASKER
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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
altariamx2003

ASKER
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
Nasir Razzaq

>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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
altariamx2003

ASKER
ok

I thing youre right

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

thanks anyway
altariamx2003

ASKER
thanks a lot for your time