|
-
Mar 17th, 2001, 02:20 AM
#1
Thread Starter
Hyperactive Member
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
-
Mar 17th, 2001, 07:10 AM
#2
Lively Member
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.
-
Mar 17th, 2001, 11:21 AM
#3
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
-
Mar 17th, 2001, 12:44 PM
#4
Thread Starter
Hyperactive Member
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?
-
Mar 17th, 2001, 02:15 PM
#5
Thread Starter
Hyperactive Member
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?
-
Mar 17th, 2001, 02:20 PM
#6
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?
-
Mar 17th, 2001, 02:24 PM
#7
I wonder how many charact
you cant redim a dimension unless it is the last dimension of an array.
-
Mar 17th, 2001, 02:27 PM
#8
Thread Starter
Hyperactive Member
I understand that... but is this because I'm using a user-defined data type? this array only has one dimension...
-
Mar 17th, 2001, 02:28 PM
#9
I wonder how many charact
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?)
-
Mar 17th, 2001, 02:33 PM
#10
Thread Starter
Hyperactive Member
it's in a module, in a procedure that calls on itself a few times.
-
Mar 17th, 2001, 02:38 PM
#11
I wonder how many charact
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)
-
Mar 17th, 2001, 02:42 PM
#12
Thread Starter
Hyperactive Member
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.
-
Mar 17th, 2001, 02:49 PM
#13
I wonder how many charact
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|