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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Two Dimension Array Length

Two Dimension Array Length

Scheduled Pinned Locked Moved Visual Basic
helpdatabasedata-structurestutorialquestion
4 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    alien viper
    wrote on last edited by
    #1

    :)Hi everyone :) Could you please help me? I would like to know the length of Two Dimension Array. Example : Dim arr(2)() as string Dim LenRank2 as Integer Dim i as int32 For i=0 to 10 arr(1)(i)=i.ToString arr(2)(i)=i.ToString Next LenRank2 = arr.GetLength(1) I got the error message "Index was outside the bounds of the array." I want to get the length of second dimension. What's wrong? Thank in advance. !alien!

    P J 2 Replies Last reply
    0
    • A alien viper

      :)Hi everyone :) Could you please help me? I would like to know the length of Two Dimension Array. Example : Dim arr(2)() as string Dim LenRank2 as Integer Dim i as int32 For i=0 to 10 arr(1)(i)=i.ToString arr(2)(i)=i.ToString Next LenRank2 = arr.GetLength(1) I got the error message "Index was outside the bounds of the array." I want to get the length of second dimension. What's wrong? Thank in advance. !alien!

      P Offline
      P Offline
      PremalathaP
      wrote on last edited by
      #2

      The error message is because of the first dimension. In VB: If you declare as arr(2), the index will start from 0. ie. arr(0) and arr(1) If you want to use arr(1) and arr(2), declare as arr(1 to 2)

      A 1 Reply Last reply
      0
      • P PremalathaP

        The error message is because of the first dimension. In VB: If you declare as arr(2), the index will start from 0. ie. arr(0) and arr(1) If you want to use arr(1) and arr(2), declare as arr(1 to 2)

        A Offline
        A Offline
        alien viper
        wrote on last edited by
        #3

        Thank you for your reply. :) Have a nice day. !alien!

        1 Reply Last reply
        0
        • A alien viper

          :)Hi everyone :) Could you please help me? I would like to know the length of Two Dimension Array. Example : Dim arr(2)() as string Dim LenRank2 as Integer Dim i as int32 For i=0 to 10 arr(1)(i)=i.ToString arr(2)(i)=i.ToString Next LenRank2 = arr.GetLength(1) I got the error message "Index was outside the bounds of the array." I want to get the length of second dimension. What's wrong? Thank in advance. !alien!

          J Offline
          J Offline
          Joshua Quick
          wrote on last edited by
          #4

          You can get the length of the inner arrays by calling Length(). Just like how you would do it with the outer array.

          Dim myArray()() As Integer = {New Integer() {1, 2, 3, 4}, _
          New Integer() {1, 2}, _
          New Integer() {1}}
          For index As Integer = 0 To (myArray.Length - 1) Step 1
          MessageBox.Show(myArray(index).Length.ToString)
          Next

          The output above will be "4", "2", and "1".

          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