-
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
-
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.
-
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
-
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?
-
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?
-
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?
-
you cant redim a dimension unless it is the last dimension of an array.
-
I understand that... but is this because I'm using a user-defined data type? this array only has one dimension...
-
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?)
-
it's in a module, in a procedure that calls on itself a few times.
-
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)
:)
-
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.
-
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....