[RESOLVED] [2005] Multi-Dimensional Array/Item Strucutre
I'm currently trying to make a vocabulary/flash-card program so I want an array that can store multiple values per item. That way I can shuffle the "cards" (array items) while keeping the word, definition, and part of speech on the same "card". So if I where to access the array I would want to be able to do something like this:
Code:
Dim vocabList as VocabArray
vocabList(0).Word = "blah"
vocabList(0).Definition = "blah"
vocabList(1).Definition = "blah"
And then if I where to re-arrange them the properties would remain together but just in a different spot of the array.
I can get really close to this using an Item Structure and declaring the variable name with () but the problem is I have to include a number with () and I need to be able to add infinite values to the array, I can't have a set number.Also I would prefer to make it like an ArrayList as it has .Add, .RemoveAt, .Insert etc. In normal Arrays there's no easy way to add, you have to resize and stuff.
Anyways here's close to what I want, but I can't have a set amount and I'd prefer the ArrayList structure so I can just have like Array.Add and then have a Item added onto the end with 3 variables on it. The only thing is that with .Add you usually put something in paranthesis after it to denote the value to add, but if I have 3 possible values then I would have to have parameters for it or something, like .Add(Word, Definition).
Code:
Structure SpecialArrayList
Public Property1 as String
Public Property2 as String
End Structure
'Random spot in program
Dim theList(2) as SpecialArrayList
theList(0).Property1 = "Blah"
etc...
Also I'm willing to look at any alternate solutions.
Re: [2005] Multi-Dimensional Array/Item Strucutre
Assuming you only want a single definition per word:
vb.net Code:
Public Class WordDefinition
Private _word As String
Private _definition As String
Public ReadOnly Property Word() As String
Get
Return Me._word
End Get
End Property
Public ReadOnly Property Definition() As String
Get
Return Me._definition
End Get
End Property
Public Sub New(ByVal word As String, ByVal definition As String)
Me._word = word
Me._definition = definition
End Sub
End Class
vb.net Code:
Dim wordDefinitions As New List(Of WordDefinition)
wordDefinitions.Add(New WordDefinition("Dog", "An animal from the canine family."))
wordDefinitions.Add(New WordDefinition("Cat", "An animal from the feline family."))
Re: [2005] Multi-Dimensional Array/Item Strucutre
I would stick with Jmc’s example but will change couple of things. First I think it will be more flexible to have the Definition field as a list of Strings so it can hold more than one definition. Also I would use Dictionary of the class and have its key set to the word so it would be fast and easy to search for a card. In this case you may or may not keep the Word property since key is the word.
Re: [2005] Multi-Dimensional Array/Item Strucutre
Quote:
Originally Posted by VBDT
I would stick with Jmc’s example but will change couple of things. First I think it will be more flexible to have the Definition field as a list of Strings so it can hold more than one definition.
That was actually how I started out when creating the example, or something like that at least, but then I figured that there was no specific indication that multiple definitions were required. If they were, I originally started with a Definitions property of type StringCollection. I was then going to change that to a ReadOnlyCollection because you probably shouldn't be able to change the list of definitions once the object has been created.
Re: [2005] Multi-Dimensional Array/Item Strucutre
Quote:
Originally Posted by jmcilhinney
That was actually how I started out when creating the example, or something like that at least, but then I figured that there was no specific indication that multiple definitions were required. If they were, I originally started with a Definitions property of type StringCollection. I was then going to change that to a ReadOnlyCollection because you probably shouldn't be able to change the list of definitions once the object has been created.
There is no doubt about it Jmc, I was just thinking a word can have more than one definition so I thought maybe he forgot to mention it. Overall your code is a great example.
Unbelievable, I started coding and was asking questions in here and you were one of many that were giving great answers. And now when I look your code examples, they are almost identical to what I would do. I think I am almost there :D Thanks for your help and the great work in VBforums.
Re: [2005] Multi-Dimensional Array/Item Strucutre
Quote:
Originally Posted by VBDT
There is no doubt about it Jmc, I was just thinking a word can have more than one definition so I thought maybe he forgot to mention it. Overall your code is a great example.
Unbelievable, I started coding and was asking questions in here and you were one of many that were giving great answers. And now when I look your code examples, they are almost identical to what I would do. I think I am almost there :D Thanks for your help and the great work in VBforums.
:thumb: and double :thumb:, although it does seem like I need to get some new tricks ;)
Re: [2005] Multi-Dimensional Array/Item Strucutre
Ok thanks that should work great. I guess I should of looked into Array(Of X) as I remembered those when looking for the solution myself but I didn't know of they could work like that.