469,354 Members | 2,035 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

Problems dynamically filling an array

Jon
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
Jul 19 '05 #1
2 2699
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" <Jo*@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

Jul 19 '05 #2
Jon
Thanks...all sorted now.

"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:%2******************@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" <Jo*@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


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by masood.iqbal | last post: by
4 posts views Thread by stephenma7 | last post: by
5 posts views Thread by Shawn Modersohn | last post: by
3 posts views Thread by yogi | last post: by
8 posts views Thread by Ray D. | last post: by
4 posts views Thread by attackwarningred | last post: by
14 posts views Thread by stevenruiz | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.