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. Declaring a array

Declaring a array

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structures
8 Posts 6 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.
  • N Offline
    N Offline
    nishkarsh_k
    wrote on last edited by
    #1

    Hello every one, I am working on a Vb.net 2005 application. I came across two ways to declare a array, i just wanted to know is there any difference between them

    Dim iTestArray() As Integer

    and

    Dim iTestArray As Integer()

    Regards Nishkarsh

    D Z 2 Replies Last reply
    0
    • N nishkarsh_k

      Hello every one, I am working on a Vb.net 2005 application. I came across two ways to declare a array, i just wanted to know is there any difference between them

      Dim iTestArray() As Integer

      and

      Dim iTestArray As Integer()

      Regards Nishkarsh

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      No, there isn't.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      • N nishkarsh_k

        Hello every one, I am working on a Vb.net 2005 application. I came across two ways to declare a array, i just wanted to know is there any difference between them

        Dim iTestArray() As Integer

        and

        Dim iTestArray As Integer()

        Regards Nishkarsh

        Z Offline
        Z Offline
        Zaegra
        wrote on last edited by
        #3

        First of all, an Array isn't the same as an Integer. An Integer can't hold multiple values. To dim an array you should use the following:

        Dim ArrayName As Array

        Or:

        Dim ArrayListName As New ArrayList

        The difference between these two is (again, as far as I know :rolleyes: ) that the size of the ArrayList is dynamically increased when needed, and that the (regular) Array doens't do this. Cheers, Zaegra

        Motivation is the key to software development.

        D 1 Reply Last reply
        0
        • Z Zaegra

          First of all, an Array isn't the same as an Integer. An Integer can't hold multiple values. To dim an array you should use the following:

          Dim ArrayName As Array

          Or:

          Dim ArrayListName As New ArrayList

          The difference between these two is (again, as far as I know :rolleyes: ) that the size of the ArrayList is dynamically increased when needed, and that the (regular) Array doens't do this. Cheers, Zaegra

          Motivation is the key to software development.

          D Offline
          D Offline
          Dave Doknjas
          wrote on last edited by
          #4

          Nishkarsh's original array declarations are absolutely correct. Your method of declaring it as 'Array' (System.Array) is generally the wrong thing to do. Declaring a variable of type 'Array' is a special purpose technique that is rarely required.

          David Anton http://www.tangiblesoftwaresolutions.com Convert VB to C#, C++, or Java Convert C# to VB, C++, or Java Convert C++ to C#, VB, or Java Convert Java to C#, C++, or VB

          Z 1 Reply Last reply
          0
          • D Dave Doknjas

            Nishkarsh's original array declarations are absolutely correct. Your method of declaring it as 'Array' (System.Array) is generally the wrong thing to do. Declaring a variable of type 'Array' is a special purpose technique that is rarely required.

            David Anton http://www.tangiblesoftwaresolutions.com Convert VB to C#, C++, or Java Convert C# to VB, C++, or Java Convert C++ to C#, VB, or Java Convert Java to C#, C++, or VB

            Z Offline
            Z Offline
            Zaegra
            wrote on last edited by
            #5

            Then please explain to me how I can store multiple values in an Integer? Because as far as I know an integer is just a number? :wtf:

            Motivation is the key to software development.

            D J 2 Replies Last reply
            0
            • Z Zaegra

              Then please explain to me how I can store multiple values in an Integer? Because as far as I know an integer is just a number? :wtf:

              Motivation is the key to software development.

              D Offline
              D Offline
              Dave Doknjas
              wrote on last edited by
              #6

              You can't store multiple values in an Integer. This is just the syntax you use when declaring arrays. i.e., Dim i() As Integer or Dim i As Integer() The parenthesis pair after either the identifier or the type indicates that it's an array of Integer, not a single Integer.

              David Anton http://www.tangiblesoftwaresolutions.com Convert VB to C#, C++, or Java Convert C# to VB, C++, or Java Convert C++ to C#, VB, or Java Convert Java to C#, C++, or VB

              1 Reply Last reply
              0
              • Z Zaegra

                Then please explain to me how I can store multiple values in an Integer? Because as far as I know an integer is just a number? :wtf:

                Motivation is the key to software development.

                J Offline
                J Offline
                Johan Hakkesteegt
                wrote on last edited by
                #7

                Zaegra wrote:

                how I can store multiple values

                Dim MyMixedValueArray() As Object

                or

                Dim MyMixedValueArray As Object()

                My advice is free, and you may get what you paid for.

                L 1 Reply Last reply
                0
                • J Johan Hakkesteegt

                  Zaegra wrote:

                  how I can store multiple values

                  Dim MyMixedValueArray() As Object

                  or

                  Dim MyMixedValueArray As Object()

                  My advice is free, and you may get what you paid for.

                  L Offline
                  L Offline
                  LCARS x32
                  wrote on last edited by
                  #8

                  I agree with David Anton. Example:

                  'Declare the array:
                  Dim myIntArray(2) as Integer

                  myIntArray(0) = 9

                  myIntArray(1) = 8

                  myIntArray(2) = myIntArray(0) - myIntArray(1) 'The value becomes 1 (9 - 8)

                  That's how it's used. -Ray

                  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