Results 1 to 4 of 4

Thread: Subscript out of range at (0) but array has been dimensioned

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Subscript out of range at (0) but array has been dimensioned

    The array variable arghashk() is redimensioned in Sub InitializeArrays yet I get error when referenced in Sub fInitCon()

    Code:
    Type tagGame
      '
      '
      arghashk() As Currency
      '
      '
    End Type
    
    Public Game As tagGame
    
    Type tagCon
      '
      '
      gc As tagGame
      '
      '
    End Type
    
    Public Sub InitializeArrays()
      '
      '
    ReDim GAME.arghashk(0 To 2048)
      '
      '
    End Sub
    
    Public Sub fInitCon()
     Dim our_con As tagCon
      '
      '
    our_con.gc.arghashk(0) = 12345 '<--Subscript out of range
      '
      '
    End Sub

    NEVERMIND - I figured it out
    Last edited by jmsrickland; Nov 28th, 2014 at 01:44 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,442

    Re: Subscript out of range at (0) but array has been dimensioned

    At what point do you call InitializeArrays?
    It APPEARS you never redimmed arghashk()
    Do you have OE set to ON?

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,476

    Re: Subscript out of range at (0) but array has been dimensioned

    This should've given you an error:
    Code:
    Public Sub InitializeArrays()
      '
      '
    ReDim tagGAME.arghashk(0 To 2048)
      '
      '
    End Sub
    tagGame is a structure prototype. The prototype's arghashk member can't be sized during runtime. Once a variable is declared as tagGame or declared as another UDT that contains a tagGame member, then that variable's arghashk can be sized.

    The only way I think you couldn't have gotten an error is "On Error Resume Next" or you declared in that routine a variable named tagGame, i.e, Dim tagGame as tagGame
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Subscript out of range at (0) but array has been dimensioned

    I figured it out as stated in my 1st post. I just wasn't doing it correctly


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width