Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Multi-Dimensional Array/Item Strucutre

  1. #1

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Resolved [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.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [2005] Multi-Dimensional Array/Item Strucutre

    Assuming you only want a single definition per word:
    vb.net Code:
    1. Public Class WordDefinition
    2.  
    3.     Private _word As String
    4.     Private _definition As String
    5.  
    6.     Public ReadOnly Property Word() As String
    7.         Get
    8.             Return Me._word
    9.         End Get
    10.     End Property
    11.  
    12.     Public ReadOnly Property Definition() As String
    13.         Get
    14.             Return Me._definition
    15.         End Get
    16.     End Property
    17.  
    18.     Public Sub New(ByVal word As String, ByVal definition As String)
    19.         Me._word = word
    20.         Me._definition = definition
    21.     End Sub
    22.  
    23. End Class
    vb.net Code:
    1. Dim wordDefinitions As New List(Of WordDefinition)
    2.  
    3. wordDefinitions.Add(New WordDefinition("Dog", "An animal from the canine family."))
    4. wordDefinitions.Add(New WordDefinition("Cat", "An animal from the feline family."))

  3. #3
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    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.

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    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 Thanks for your help and the great work in VBforums.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    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 Thanks for your help and the great work in VBforums.
    and double , although it does seem like I need to get some new tricks

  7. #7

    Thread Starter
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    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.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width