Results 1 to 13 of 13

Thread: Brain Dead

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Why am I getting a subscript error (9) from this:

    Type HandleInformation
    HWnd As Long
    ParentHWnd As Long
    Process As Long
    Thread As Long
    Class As String
    Exe As String
    End Type

    Public HList() As HandleInformation

    --------------

    For a = 1 to 5
    ReDim Preserve HList(UBound(HList) + 1) As HandleInformation
    Next

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94

    Smile Possibly...

    I'm not sure, but possibly because when you execute this line:

    ReDim Preserve HList(UBound(HList) + 1) As HandleInformation

    the array HList dosn't have anything in it first time. Maybe the UBound function can't deal with empty arrays.

    You could try making the first case a special case and the leave your code as it is for the remainder of the loop.

    Gulliver.

  3. #3
    Guest
    That's correct, since the array is dynamic, it does not have a UBound, hence just create it yourself because you loop through and create more.
    Code:
    ReDim Preserve HList(0) As HandleInformation
    
    For a = 1 To 5
        ReDim Preserve HList(UBound(HList) + 1) As HandleInformation
    Next

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    I thought of those solutions already... and I get the same error just by putting:

    ReDim Preserve HList(0) As HandleInformation

    above the spot in the code. Any ideas?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    I figured out this much:

    ReDim Preserve HList(0) As HandleInformation

    For a = 1 To 5
    ReDim HList(UBound(HList) + 1) As HandleInformation
    Next

    This works, problem is, I had to take Preserve out of the for loop. Okay, any sparks out there?

  6. #6
    Guest
    Code:
    ReDim Preserve HList(0) As HandleInformation
    
    For a = 1 To 5
        ReDim Preserve HList(UBound(HList) + 1) As HandleInformation
    Next
    This seems to work for me. Do you still get the same error message? Or is it a different one?

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    you cant redim a dimension unless it is the last dimension of an array.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    I understand that... but is this because I'm using a user-defined data type? this array only has one dimension...

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    if you put the code you have into a start up module
    and make a sub called sub main()
    and put your for loop into the sub, it works...



    so,
    where are you using the for loop (in a form, module what?)

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    it's in a module, in a procedure that calls on itself a few times.

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    hmmm... recursion

    Does it execute one time properly?
    If so, then it has something to do with the fact that it
    calls itself...

    These are just off the brain ideas im not putting much thought behind them...(obviously)

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Haha, that's okay... no, it doesn't get through even once... I think it has something to do with the fact that I'm using a user-defined datatype with it.

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    1 last thing

    if you do go and put your code into a new project...
    you'll see it works... so it must be something else in your app thats mutzing it....

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