HELP: Subscript out of range error (array) - CONFUSED!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VB Programmer

    HELP: Subscript out of range error (array) - CONFUSED!

    I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
    version 6....

    I need help for something that should be simple. I keep getting a
    "subscript out of range" error and don't know why. Briefly....

    I have an array of Variants dimmed as this:
    Global gMyConnection() As Variant

    I redim it later like this:
    ReDim gMyConnection(6 6)

    In a FOR loop (For i = 0 to 65) I am doing this:
    Set gMyConnection(i ) = New MyClass
    * NOTE: There is no class_initializ e in the MyClass class.

    On this "Set" line, when i = 65, I keep getting an "Error 9 subscript out of
    range" error. It works for i = 0 to i = 64.

    Any ideas?



  • Herfried K. Wagner [MVP]

    #2
    Re: HELP: Subscript out of range error (array) - CONFUSED!

    * "VB Programmer" <growNO-SPAM@go-intech.com> scripsit:[color=blue]
    > I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
    > version 6....[/color]

    microsoft.publi c.vb.* is the place you are looking for!

    --
    Herfried K. Wagner [MVP]
    <http://www.mvps.org/dotnet>

    Comment

    • VB Programmer

      #3
      Re: HELP: Subscript out of range error (array) - CONFUSED!

      Thanks. I posted there too.

      Still, if anyone can help, I would appreciate it!

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:bu3qr4$de5 od$3@ID-208219.news.uni-berlin.de...[color=blue]
      > * "VB Programmer" <growNO-SPAM@go-intech.com> scripsit:[color=green]
      > > I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup[/color][/color]
      for[color=blue][color=green]
      > > version 6....[/color]
      >
      > microsoft.publi c.vb.* is the place you are looking for!
      >
      > --
      > Herfried K. Wagner [MVP]
      > <http://www.mvps.org/dotnet>[/color]


      Comment

      • One Handed Man [ OHM# ]

        #4
        Re: Subscript out of range error (array) - CONFUSED!

        I dont remember if VB6 have upper bound initialisers of not ?, In VB.NET the
        subscript on initialisation is the upper bound so for example myarray(7)
        would have 8 elements ( 0 - 7 ).

        In VB6, If this is the number of elements rather than the upper bound ( get
        my drift ) then for an initialisation of myarray(7), the elements would be
        ( 0 - 6 ).

        HTH - Regards - OHM




        VB Programmer wrote:[color=blue]
        > I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup
        > for version 6....
        >
        > I need help for something that should be simple. I keep getting a
        > "subscript out of range" error and don't know why. Briefly....
        >
        > I have an array of Variants dimmed as this:
        > Global gMyConnection() As Variant
        >
        > I redim it later like this:
        > ReDim gMyConnection(6 6)
        >
        > In a FOR loop (For i = 0 to 65) I am doing this:
        > Set gMyConnection(i ) = New MyClass
        > * NOTE: There is no class_initializ e in the MyClass class.
        >
        > On this "Set" line, when i = 65, I keep getting an "Error 9 subscript
        > out of range" error. It works for i = 0 to i = 64.
        >
        > Any ideas?[/color]

        --
        Best Regards - OHM

        O_H_M{at}BTInte rnet{dot}com


        Comment

        • Tom Leylan

          #5
          Re: HELP: Subscript out of range error (array) - CONFUSED!

          "VB Programmer" <growNO-SPAM@go-intech.com> wrote...[color=blue]
          > Thanks. I posted there too.
          > Still, if anyone can help, I would appreciate it![/color]

          Hopefully I can help... first there doesn't appear to be anything wrong
          with the code you've posted except that you should be able to intialize
          element 66 also.

          Which leads me to believe the code may not be exactly has you posted. In
          these situations I'll tell you what I do. Eliminate anything else that
          could be the cause of the problem, get it to work as expected and then add
          code back a few lines at a time.

          So... in your case comment out the class assignments. Since you have the
          array as variants just plop a string in it something like:

          gMyConnection(i ) = "test " & CStr(i)

          Have the loop fill the array and then have a second loop print the array
          elements. It works for me so I can't imagine it won't work for you.

          Tom



          Comment

          • VB Programmer

            #6
            Re: HELP: Subscript out of range error (array) - CONFUSED!

            Thanks for your help and advice!

            "Tom Leylan" <gee@iamtiredof spam.com> wrote in message
            news:egHevns2DH A.2604@TK2MSFTN GP09.phx.gbl...[color=blue]
            > "VB Programmer" <growNO-SPAM@go-intech.com> wrote...[color=green]
            > > Thanks. I posted there too.
            > > Still, if anyone can help, I would appreciate it![/color]
            >
            > Hopefully I can help... first there doesn't appear to be anything wrong
            > with the code you've posted except that you should be able to intialize
            > element 66 also.
            >
            > Which leads me to believe the code may not be exactly has you posted. In
            > these situations I'll tell you what I do. Eliminate anything else that
            > could be the cause of the problem, get it to work as expected and then add
            > code back a few lines at a time.
            >
            > So... in your case comment out the class assignments. Since you have the
            > array as variants just plop a string in it something like:
            >
            > gMyConnection(i ) = "test " & CStr(i)
            >
            > Have the loop fill the array and then have a second loop print the array
            > elements. It works for me so I can't imagine it won't work for you.
            >
            > Tom
            >
            >
            >[/color]


            Comment

            • VB Programmer

              #7
              Re: Subscript out of range error (array) - CONFUSED!

              Thanks alot.

              "One Handed Man [ OHM# ]" <O_H_M{at}BTInt ernet{dot}com> wrote in message
              news:OIbbTbs2DH A.3196@TK2MSFTN GP11.phx.gbl...[color=blue]
              > I dont remember if VB6 have upper bound initialisers of not ?, In VB.NET[/color]
              the[color=blue]
              > subscript on initialisation is the upper bound so for example myarray(7)
              > would have 8 elements ( 0 - 7 ).
              >
              > In VB6, If this is the number of elements rather than the upper bound ([/color]
              get[color=blue]
              > my drift ) then for an initialisation of myarray(7), the elements would be
              > ( 0 - 6 ).
              >
              > HTH - Regards - OHM
              >
              >
              >
              >
              > VB Programmer wrote:[color=green]
              > > I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup
              > > for version 6....
              > >
              > > I need help for something that should be simple. I keep getting a
              > > "subscript out of range" error and don't know why. Briefly....
              > >
              > > I have an array of Variants dimmed as this:
              > > Global gMyConnection() As Variant
              > >
              > > I redim it later like this:
              > > ReDim gMyConnection(6 6)
              > >
              > > In a FOR loop (For i = 0 to 65) I am doing this:
              > > Set gMyConnection(i ) = New MyClass
              > > * NOTE: There is no class_initializ e in the MyClass class.
              > >
              > > On this "Set" line, when i = 65, I keep getting an "Error 9 subscript
              > > out of range" error. It works for i = 0 to i = 64.
              > >
              > > Any ideas?[/color]
              >
              > --
              > Best Regards - OHM
              >
              > O_H_M{at}BTInte rnet{dot}com
              >
              >[/color]


              Comment

              • VB Programmer

                #8
                Re: Subscript out of range error (array) - CONFUSED!

                SORRY ABOUT THE DATE/TIME OF THIS THREAD. I DIDN'T REALIZE BY CLOCK WAS
                AHEAD BY 1 DAY. I HAVE FIXED IT. SORRY AND THANKS ONCE AGAIN EVERYONE!

                "VB Programmer" <growNO-SPAM@go-intech.com> wrote in message
                news:euQKekr2DH A.2460@TK2MSFTN GP10.phx.gbl...[color=blue]
                > I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
                > version 6....
                >
                > I need help for something that should be simple. I keep getting a
                > "subscript out of range" error and don't know why. Briefly....
                >
                > I have an array of Variants dimmed as this:
                > Global gMyConnection() As Variant
                >
                > I redim it later like this:
                > ReDim gMyConnection(6 6)
                >
                > In a FOR loop (For i = 0 to 65) I am doing this:
                > Set gMyConnection(i ) = New MyClass
                > * NOTE: There is no class_initializ e in the MyClass class.
                >
                > On this "Set" line, when i = 65, I keep getting an "Error 9 subscript out[/color]
                of[color=blue]
                > range" error. It works for i = 0 to i = 64.
                >
                > Any ideas?
                >
                >
                >[/color]


                Comment

                • Rob Richardson

                  #9
                  Re: Subscript out of range error (array) - CONFUSED!

                  OHM,

                  VB6 works the same way as .Net does in this regard. MyArray(7) gives you
                  elements with indexes 0-7 (8 elements).

                  Rob


                  Comment

                  Working...