Re: simple and yet stupid question... Please help
- From: "tw" <tlsilveus@xxxxxxxxxxx>
- Date: Thu, 26 May 2005 09:46:34 -0700
It only doen't work if the function passes back an array with no values.
The function has a private array that gets redimmed to the appropriate
value. It is that array that is passed back into the array in this sub.
Thanks for your help. I understand it a little better now.
"Ken Snell [MVP]" <kthsneisllis9@xxxxxxxxxxxxxxxxxx> wrote in message
news:ODHaJrgYFHA.2572@xxxxxxxxxxxxxxxxxxxxxxx
> When you use this type of dim:
> Dim arrUsersInGroup() as string
>
> your code at some point must redimension the array, example:
> ReDim arrUsersInGroup(15) As String
>
> Until you do the ReDim, the array has no size and thus the subscripts will
> be out of range because there is no range.
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
>
>
> "tw" <tlsilveus@xxxxxxxxxxx> wrote in message
> news:OJOXmfgYFHA.3188@xxxxxxxxxxxxxxxxxxxxxxx
>>I DIMmed the array like this
>>
>> Dim arrUsersInGroup() as string
>>
>> I then call a routine that fills an array and returns it like this
>> arrUsersInGroup = ListUsersOfGroup(arrGroupList(loop1count))
>> in the code below and at For Each loop2 In arrUsersInGroup
>> is where I got the subscript out of range when there were no elements.
>> So I modified ListUsersOfGroup() to return at least one element. But if
>> I dim the array like this dim arrUsersInGroup as string can I return an
>> array to it from the function ListUsersOfGroup() without an error?
>>
>> loop1count = 0
>> loop2count = 0
>> For Each loop1 In arrGroupList
>> strWriteString = strWriteString & vbCrLf & vbTab &
>> arrGroupList(loop1count)
>> arrUsersInGroup = ListUsersOfGroup(arrGroupList(loop1count))
>> For Each loop2 In arrUsersInGroup
>> strWriteString = strWriteString & vbCrLf & vbTab & vbTab &
>> arrUsersInGroup(loop2count)
>> loop2count = loop2count + 1
>> Next
>> loop1count = loop1count + 1
>> loop2count = 0
>> Next
>>
>>
>>
>> "Ken Snell [MVP]" <kthsneisllis9@xxxxxxxxxxxxxxxxxx> wrote in message
>> news:uJ7npWYYFHA.1092@xxxxxxxxxxxxxxxxxxxxxxx
>>> How do you Dim the array variable?
>>>
>>> If you use this:
>>> Dim varArray()
>>>
>>> or this
>>> Dim varArray(4)
>>>
>>> or this
>>> Dim varArray(1 To 3)
>>>
>>> then IsArray will return positive.
>>>
>>> If you use this
>>> Dim varArray
>>>
>>> then it won't show as an array until you fill it from the Split function
>>> or some other filling excercise.
>>>
>>> You don't tell me any more details about the code that is giving the
>>> subscript out of range error, so I cannot speak to that.
>>>
>>> --
>>>
>>> Ken Snell
>>> <MS ACCESS MVP>
>>>
>>>
>>> "tw" <tw@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>> news:EC2D13B6-EE9D-4131-B7CC-E6ECCF94F414@xxxxxxxxxxxxxxxx
>>>>I don't know what I'm doing wrong then. I tried isarray(thearray) in
>>>>the
>>>> immediate window while it was suspended for debugging and it returned
>>>> true
>>>> even though there where no elements in the array. I got around it by
>>>> adding
>>>> to my function that returns the array to fill the first element with a
>>>> no
>>>> information message so that at least one element would be present.
>>>> That
>>>> works for this part of my program, but I would like to know what I was
>>>> doing
>>>> wrong so I don't run into this problem in the future. I can post my
>>>> original
>>>> code if you think it might help.
>>>>
>>>> "Ken Snell [MVP]" wrote:
>>>>
>>>>> Just test the variable with the IsArray function. If result is True,
>>>>> the
>>>>> variable contains at least one element in the array.
>>>>>
>>>>> --
>>>>>
>>>>> Ken Snell
>>>>> <MS ACCESS MVP>
>>>>>
>>>>> "tw" <tw@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>>>> news:479E262C-33E9-4BD7-9189-2C1E5E3ED5B8@xxxxxxxxxxxxxxxx
>>>>> > Sorry, I my thought processes weren't completely working when I
>>>>> > posted
>>>>> > this.
>>>>> > I tried ubound and lbound. My problem is that sometimes there are
>>>>> > no
>>>>> > elements in the array and I'm getting subscript out of range or
>>>>> > array not
>>>>> > initialized when i used it in a for each x in thearray.
>>>>> >
>>>>> > "Ken Snell [MVP]" wrote:
>>>>> >
>>>>> >> NumberOfElementsInArray = UBound(ArrayVariable0 -
>>>>> >> LBound(ArrayVariable) +
>>>>> >> 1
>>>>> >>
>>>>> >> --
>>>>> >>
>>>>> >> Ken Snell
>>>>> >> <MS ACCESS MVP>
>>>>> >>
>>>>> >> "tw" <tw@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>>>> >> news:C9853111-AAC1-4799-92E7-782A32CF4436@xxxxxxxxxxxxxxxx
>>>>> >> > I'm filling an array in a function then returning the array to
>>>>> >> > the
>>>>> >> > calling
>>>>> >> > procedure. I need the calling procedure to know if the array has
>>>>> >> > any
>>>>> >> > contents. How can I determine the count of elements of an array?
>>>>> >> >
>>>>> >> >
>>>>> >>
>>>>> >>
>>>>> >>
>>>>>
>>>>>
>>>>>
>>>
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: simple and yet stupid question... Please help
- From: Ken Snell [MVP]
- Re: simple and yet stupid question... Please help
- References:
- simple and yet stupid question... Please help
- From: tw
- Re: simple and yet stupid question... Please help
- From: Ken Snell [MVP]
- Re: simple and yet stupid question... Please help
- From: tw
- Re: simple and yet stupid question... Please help
- From: Ken Snell [MVP]
- Re: simple and yet stupid question... Please help
- From: tw
- Re: simple and yet stupid question... Please help
- From: Ken Snell [MVP]
- Re: simple and yet stupid question... Please help
- From: tw
- Re: simple and yet stupid question... Please help
- From: Ken Snell [MVP]
- simple and yet stupid question... Please help
- Prev by Date: Re: Join Split Database
- Next by Date: Re: simple and yet stupid question... Please help
- Previous by thread: Re: simple and yet stupid question... Please help
- Next by thread: Re: simple and yet stupid question... Please help
- Index(es):
Relevant Pages
|