Hi all,

I am trying to dynamically fill an array with any unique values from a field
(objRS.Fields(5)) in my database with the following code below. However it
errors with "The array is fixed or temporarily blocked" for the line "REDIM
PRESERVE UserArray(Arraycount+1)". I can't seem to get around this. Any
suggestions? Many thanks.

Dim p
Dim UserArray(0) ' Max number of users
Dim Arraycount
Dim flag
objRS.MoveFirst
Do While Not objRS.EOF
p = 0
flag = false
'--Check if username is already in the array
Arraycount = UBound(UserArray)
do while (p <= Arraycount) And (flag = false)
if objRS.Fields(5) = UserArray(p) then flag = true
P=P+1
loop
if (flag = false) then ' name not in array
UserArray(Arraycount) = objRS.Fields(5)
REDIM PRESERVE UserArray(Arraycount+1)
End if
objRS.MoveNext
Loop

Re: Problems dynamically filling an array by Ray

Ray
Thu May 06 22:42:28 CDT 2004

Try Dim UserArray() instead of Dim UserArray(0)

Dymamic arrays are dimmed just as () as the ubound.

But, why not just just select distinct or something when you create your
recordset? And if not, why use that flag thing? You can just do:


Do While Not objRS.EOF
If objRS.Fields.Item(5).Value = UserArray Then
Redim Preserve UserArray(ArrayCount+1)
UserArray(UBound(UserArray)) = objRS.Fields.Item(5).Value
Exit Do
End If
p = p + 1
objRS.MoveNext
Loop

Ray at home

"Jon" <Jon@nospam.com> wrote in message
news:64Bmc.408$VR4.390@newsfe1-win...
> Hi all,
>
> I am trying to dynamically fill an array with any unique values from a
field
> (objRS.Fields(5)) in my database with the following code below. However
it
> errors with "The array is fixed or temporarily blocked" for the line
"REDIM
> PRESERVE UserArray(Arraycount+1)". I can't seem to get around this. Any
> suggestions? Many thanks.
>
> Dim p
> Dim UserArray(0) ' Max number of users
> Dim Arraycount
> Dim flag
> objRS.MoveFirst
> Do While Not objRS.EOF
> p = 0
> flag = false
> '--Check if username is already in the array
> Arraycount = UBound(UserArray)
> do while (p <= Arraycount) And (flag = false)
> if objRS.Fields(5) = UserArray(p) then flag = true
> P=P+1
> loop
> if (flag = false) then ' name not in array
> UserArray(Arraycount) = objRS.Fields(5)
> REDIM PRESERVE UserArray(Arraycount+1)
> End if
> objRS.MoveNext
> Loop
>
>



Re: Problems dynamically filling an array by Jon

Jon
Sun May 09 17:15:36 CDT 2004

Thanks...all sorted now.

"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:%23DQqsU%23MEHA.3012@tk2msftngp13.phx.gbl...
> Try Dim UserArray() instead of Dim UserArray(0)
>
> Dymamic arrays are dimmed just as () as the ubound.
>
> But, why not just just select distinct or something when you create your
> recordset? And if not, why use that flag thing? You can just do:
>
>
> Do While Not objRS.EOF
> If objRS.Fields.Item(5).Value = UserArray Then
> Redim Preserve UserArray(ArrayCount+1)
> UserArray(UBound(UserArray)) = objRS.Fields.Item(5).Value
> Exit Do
> End If
> p = p + 1
> objRS.MoveNext
> Loop
>
> Ray at home
>
> "Jon" <Jon@nospam.com> wrote in message
> news:64Bmc.408$VR4.390@newsfe1-win...
> > Hi all,
> >
> > I am trying to dynamically fill an array with any unique values from a
> field
> > (objRS.Fields(5)) in my database with the following code below. However
> it
> > errors with "The array is fixed or temporarily blocked" for the line
> "REDIM
> > PRESERVE UserArray(Arraycount+1)". I can't seem to get around this.
Any
> > suggestions? Many thanks.
> >
> > Dim p
> > Dim UserArray(0) ' Max number of users
> > Dim Arraycount
> > Dim flag
> > objRS.MoveFirst
> > Do While Not objRS.EOF
> > p = 0
> > flag = false
> > '--Check if username is already in the array
> > Arraycount = UBound(UserArray)
> > do while (p <= Arraycount) And (flag = false)
> > if objRS.Fields(5) = UserArray(p) then flag = true
> > P=P+1
> > loop
> > if (flag = false) then ' name not in array
> > UserArray(Arraycount) = objRS.Fields(5)
> > REDIM PRESERVE UserArray(Arraycount+1)
> > End if
> > objRS.MoveNext
> > Loop
> >
> >
>
>