Hi,
I’m taking input from a user and need to stick it into an array, the problem is, I don’t know ahead of time how many dimensions the array will have and I also don’t know how many items the user will want to stick in each dimension.
The array will have a maximum number of dimensions of 4, but an unlimited number of items per dimension.
I’m trying to create an unordered html list creator, so I need to know the number of items in each level of the list, and since (As far as I know) you can’t create a multi dimensional array with a dynamic size, I’m feeling a little stuck.
I’ve heard that you can use an object to cater for this kind of thing, but both array and object creation is a little new to me.
Can anyone point me in the right direction please?
I’m familiar with list <of T> and I’m not sure if it’s appropriate for what I’m trying to do.
I want to be able to allow a user to type in the items of a menu in terms of their levels and define their relationships.
So I’ll need to allow the person to first specify how many levels depth the menu goes, then populate 1 item from each level until the last level where they will list all items that belong to the 2nd from final level.
For example:
menu level1 = vehicles
level2 = cars
level3 =toyota (Though with the latest news I wouldn’t by one)
level4= red,blue,green,purple,orange etc
Then repeat the process for vehicles, cars, FORD
When they’ve defined a full path and all children items of the 3rd level they press a button to write what they’ve added to an array. Repeat until menu is complete.
I did consider using standard lists, but I would think it would be much more difficult to create the structure and relationships that I’ve described above.
You are thinking a bit too concretely here, rather you need a MenuItem class that has a (nullable) Parent property which is a MenuItem. Then you just need a list of the parents and you can drill down to the children recursively.
That was way over my head.
As I said, I’m pretty new to object creation, so I need to take baby steps.
I made an attempt with arrays and I got up to the point where I realized that I had wasted my time.
I thought that I could say that each dimension in the array could store it’s own static data, for example, if my array has 4 dimensions, the first dimension contains the highest level menu item and the 4th dimension contains the lowest.
As I said I’m new to objects and classes.
Have I implemented the class correctly?
Public Class menuItem
Public ItemID As Integer
Public ParentID As Integer
Public MenuText As String
Public Property menuItemID() As String
Get
' Gets the property value.
Return ItemID
End Get
Set(ByVal Value As String)
' Sets the property value.
ItemID = Value
End Set
End Property
Public Property ParentMenuItemID() As String
Get
' Gets the property value.
Return ParentID
End Get
Set(ByVal Value As String)
' Sets the property value.
ParentID = Value
End Set
End Property
Public Property MenuItemText() As String
Get
' Gets the property value.
Return MenuText
End Get
Set(ByVal Value As String)
' Sets the property value.
MenuText = Value
End Set
End Property
End Class