Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Array inside array

Array inside array

Scheduled Pinned Locked Moved Visual Basic
data-structureshelptutorialquestion
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tatchung
    wrote on last edited by
    #1

    Hello everyone, Is it possible to store an array inside an array? Like for example I have these logs below array1(0) 2007-05-17 04:25:30 Receive 2007-05-17 04:25:31 Sent 2007-05-17 04:25:31 Sent 2007-05-17 04:25:34 DLR array1(1) 2007-05-17 04:32:18 Receive 2007-05-17 04:32:19 Sent 2007-05-17 04:32:19 Sent array1(2) 2007-05-17 04:37:03 Receive 2007-05-17 04:37:04 Sent 2007-05-17 04:37:04 Sent 2007-05-17 04:37:04 Sent Then for each array1 element I can create another array (array2) to store each line separately for "Received", "Sent" and "DLR". So I was thinking it would look something like array1(0(array2(0)). Many thanks in advance for any help, suggestions given :-D

    Aim small, miss small

    G 1 Reply Last reply
    0
    • T tatchung

      Hello everyone, Is it possible to store an array inside an array? Like for example I have these logs below array1(0) 2007-05-17 04:25:30 Receive 2007-05-17 04:25:31 Sent 2007-05-17 04:25:31 Sent 2007-05-17 04:25:34 DLR array1(1) 2007-05-17 04:32:18 Receive 2007-05-17 04:32:19 Sent 2007-05-17 04:32:19 Sent array1(2) 2007-05-17 04:37:03 Receive 2007-05-17 04:37:04 Sent 2007-05-17 04:37:04 Sent 2007-05-17 04:37:04 Sent Then for each array1 element I can create another array (array2) to store each line separately for "Received", "Sent" and "DLR". So I was thinking it would look something like array1(0(array2(0)). Many thanks in advance for any help, suggestions given :-D

      Aim small, miss small

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      tatchung wrote:

      So I was thinking it would look something like array1(0(array2(0)).

      Not quite. An array is an object, so it doesn't have a name in itself. What you name is the reference variable that holds a reference to the array. So, you don't name the arrays that you store in the array. You only have a name for the variable referencing the outer array:

      Dim array1(3)() As String
      array1(0) = new String() { "Receive", "Sent", "Sent", "DLR" }
      array1(1) = new String() { "Receive", "Sent", "Sent" }
      array1(2) = new String() { "Receive", "Sent", "Sent", "Sent" }

      You can create a string array to store in the array. You would have a reference variable for that array too, but you still only store the reference to the string array in the outer array:

      Dim x(1) As String
      x(0) = "Receive"
      x(1) = "Sent"
      array1(3) = x 'Puts the reference in the outer array

      To use the arrays you only use the single variable name that you have. The value of the expression array1(0) is a string array, so you just stack another index after that expression to access a string:

      array1(0)(1)

      Despite everything, the person most likely to be fooling you next is yourself.

      T 1 Reply Last reply
      0
      • G Guffa

        tatchung wrote:

        So I was thinking it would look something like array1(0(array2(0)).

        Not quite. An array is an object, so it doesn't have a name in itself. What you name is the reference variable that holds a reference to the array. So, you don't name the arrays that you store in the array. You only have a name for the variable referencing the outer array:

        Dim array1(3)() As String
        array1(0) = new String() { "Receive", "Sent", "Sent", "DLR" }
        array1(1) = new String() { "Receive", "Sent", "Sent" }
        array1(2) = new String() { "Receive", "Sent", "Sent", "Sent" }

        You can create a string array to store in the array. You would have a reference variable for that array too, but you still only store the reference to the string array in the outer array:

        Dim x(1) As String
        x(0) = "Receive"
        x(1) = "Sent"
        array1(3) = x 'Puts the reference in the outer array

        To use the arrays you only use the single variable name that you have. The value of the expression array1(0) is a string array, so you just stack another index after that expression to access a string:

        array1(0)(1)

        Despite everything, the person most likely to be fooling you next is yourself.

        T Offline
        T Offline
        tatchung
        wrote on last edited by
        #3

        Aha! So i just have to add the element number of the inner array when i call upon the outer array. Many thanks Sir! Sorry about this but I forgot to mention I'm using vb6. Is this still applicable or is this already for .NET?

        Aim small, miss small

        G 1 Reply Last reply
        0
        • T tatchung

          Aha! So i just have to add the element number of the inner array when i call upon the outer array. Many thanks Sir! Sorry about this but I forgot to mention I'm using vb6. Is this still applicable or is this already for .NET?

          Aim small, miss small

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          It should work just fine in VB6, but the syntax isn't exactly the same. It's called a jagged array if you want to look for code examples.

          tatchung wrote:

          Aim small, miss small

          "The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it." Michelangelo :)

          Despite everything, the person most likely to be fooling you next is yourself.

          T 1 Reply Last reply
          0
          • G Guffa

            It should work just fine in VB6, but the syntax isn't exactly the same. It's called a jagged array if you want to look for code examples.

            tatchung wrote:

            Aim small, miss small

            "The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it." Michelangelo :)

            Despite everything, the person most likely to be fooling you next is yourself.

            T Offline
            T Offline
            tatchung
            wrote on last edited by
            #5

            Guffa wrote:

            "The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it."

            Great! That just changed my views. :-D Got the code and it looks something like this:

            Dim aTest(1 To 2) As Variant
            Dim bTest(1 To 1) As Variant
            aTest(1) = 1
            aTest(2) = 2
            bTest(1) = aTest
            MsgBox bTest(1)(1)
            MsgBox bTest(1)(2)

            ...for future reference. ;) Thanks again for the help, not to mention the enlightenment :laugh:

            Aim small, miss small

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups