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. a problem in array in vb.net

a problem in array in vb.net

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdata-structures
9 Posts 4 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.
  • H Offline
    H Offline
    Hasan Jaffal
    wrote on last edited by
    #1

    i use arrays in vb.net but i have a problem in the dimension ex : dim a() as integer a(0)=new integer gives error i don't want to use arraylist because i dound inutil to do the cast

    K N 2 Replies Last reply
    0
    • H Hasan Jaffal

      i use arrays in vb.net but i have a problem in the dimension ex : dim a() as integer a(0)=new integer gives error i don't want to use arraylist because i dound inutil to do the cast

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      Could you display your real code please? What are you really setting a(0) equal to? I mean, you are not actually setting it to New Integer right? You are setting it to an actual value? And what is the error that you are getting?

      H 1 Reply Last reply
      0
      • K Kschuler

        Could you display your real code please? What are you really setting a(0) equal to? I mean, you are not actually setting it to New Integer right? You are setting it to an actual value? And what is the error that you are getting?

        H Offline
        H Offline
        Hasan Jaffal
        wrote on last edited by
        #3

        i'm defining a vector without defining its size so when i make new to allocate in memory i get the eror : not set to an instance

        K 1 Reply Last reply
        0
        • H Hasan Jaffal

          i use arrays in vb.net but i have a problem in the dimension ex : dim a() as integer a(0)=new integer gives error i don't want to use arraylist because i dound inutil to do the cast

          N Offline
          N Offline
          nlarson11
          wrote on last edited by
          #4

          dim a() as integer array.Resize(a,0) ' or redim preserve a(0) a(0) = 9999

          H 1 Reply Last reply
          0
          • H Hasan Jaffal

            i'm defining a vector without defining its size so when i make new to allocate in memory i get the eror : not set to an instance

            K Offline
            K Offline
            Kschuler
            wrote on last edited by
            #5

            I haven't been able to get through this error without defining the size of the array upfront. If you are using Visual Studio 2005 you can use a List object instead. It is like an ArrayList except that you must declare what type of objects are being listed, so you will not have to worry about the overhead of casting the objects into what you want. Here's how you declare it: Dim objList As New List(Of Integer) Hope this helps.

            1 Reply Last reply
            0
            • N nlarson11

              dim a() as integer array.Resize(a,0) ' or redim preserve a(0) a(0) = 9999

              H Offline
              H Offline
              Hasan Jaffal
              wrote on last edited by
              #6

              thanks that's work now i have a bigger question if a fuction return a vector public function f() as integer () dim a() as integer redim preserve a(0) redim preserve a(1) a(0)=1 a(1)=0 return a end function ----------------------------------- dim k () as integer k=f() msgbox(k(0)) ------->gives error : not set to instance

              N 1 Reply Last reply
              0
              • H Hasan Jaffal

                thanks that's work now i have a bigger question if a fuction return a vector public function f() as integer () dim a() as integer redim preserve a(0) redim preserve a(1) a(0)=1 a(1)=0 return a end function ----------------------------------- dim k () as integer k=f() msgbox(k(0)) ------->gives error : not set to instance

                N Offline
                N Offline
                nlarson11
                wrote on last edited by
                #7
                1. if you know how many you'll have you can do a 'static' array dim a(1) as integer 'creates 0 both instances 0 and 1 2) you don't need to do a redim twice if you know how big you want to make it. redim preserve a(1) 'will create both instances 0 and 1 3) ran you code... ran fine for me...???
                H 1 Reply Last reply
                0
                • N nlarson11
                  1. if you know how many you'll have you can do a 'static' array dim a(1) as integer 'creates 0 both instances 0 and 1 2) you don't need to do a redim twice if you know how big you want to make it. redim preserve a(1) 'will create both instances 0 and 1 3) ran you code... ran fine for me...???
                  H Offline
                  H Offline
                  Hasan Jaffal
                  wrote on last edited by
                  #8

                  man thanks but the problem is when the functon return the vector ... it allways be null

                  T 1 Reply Last reply
                  0
                  • H Hasan Jaffal

                    man thanks but the problem is when the functon return the vector ... it allways be null

                    T Offline
                    T Offline
                    TwoFaced
                    wrote on last edited by
                    #9

                    Maybe you should post a bigger junk of code or help explain the situation in further detail . I tested your code also and it works perfectly. Something else has to be going on.

                    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