[RESOLVED] array names algorithm-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] array names algorithm

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    23

    Resolved [RESOLVED] array names algorithm

    I need to write an algorithm that can automatically read a string into up to 50 arrays. The name of each array is valuearray followed by the array number i.e. the 3rd array would be valuearray3()

    What i want to be able to do is write an alogrithm that reads the contents into each array without having to declare each array i.e.

    Dim valuearray1() as string = text
    Dim valuearray2() as string = text
    Dim valuearray3() as string = text
    ...
    Dim valuearray50() as string = text

    What i want is an algorithm that functions something like this:
    declarations
    Dim text As String = "String"
    Dim arrayindex As Intger
    Dim index As Integer

    Algorithm
    For index = 1 To 50
    "valuearray" + index + "(1)" = text
    arrayindex += 1
    Next index

    This algorithm would add the text "string" into the first index of each array from valuearray1 to valuearray50

    the only problem is that i don't know how code it in VB. It's be appreciated if you could help
    Last edited by BumpaPumpa; Jun 21st, 2015 at 02:33 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,474

    Re: array names algorithm

    use a List(Of List(of String))

    Code:
    Dim a As New List(Of List(Of String))
    a.Add(New List(Of String))
    a.Last.Add("a string")

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    23

    Re: array names algorithm

    would you mind incorporating that example into my loop?

  4. #4
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,198

    Re: array names algorithm

    although a list is a great tool most of the times and if you, Bumpa are not yet familiar with it you should certainly read up on it, i think that you are more asking for a multidimensional array.

    Code:
            Dim MultidimensionalArray(50, 50) As String
    
            For iRow As Int32 = 0 To MultidimensionalArray.GetUpperBound(0)
                For iCol As Int32 = 0 To MultidimensionalArray.GetUpperBound(1)
                    MultidimensionalArray(iRow, iCol) = String.Format("row {0}, column {1}", iRow, iCol)
                Next
            Next

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    23

    Re: array names algorithm

    Thanks! that was exactly what i was looking for.

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.