473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2821
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece...
7
by: masood.iqbal | last post by:
I am having lots of trouble getting a simple program that initializs a dynamically allocated 2D array to work. My 2D array is not getting initialized properly, and additionally I am getting a...
4
by: stephenma7 | last post by:
Hi, everybody. I am new here. I have encountered these many problems for the last couple of days. I have Linux Fedora Core 3(Gnu G++ 3.4.2), Linux Fedora Core 2 (Gnu G++ 3.3.3), Red Hat 9 (Gnu...
5
by: Shawn Modersohn | last post by:
For the script: <script language="JavaScript"> function pullPage(){ var arrayLength=document.teamSelectionF.teamSelectionS.length; var pageNav = new Array(arrayLength); var...
6
by: Sjaakie | last post by:
Hi there, I'm trying to get this working with Firefox. Can you point out what's wrong? No problems with IE, Firefox doens't fill selMonth... TIA >>> the script... >>> <select name="selDay"...
3
by: yogi | last post by:
Hi guys, I'm trying to write a program that will read in a series of files and create a 3D array from the files read in for converting 2D images to 3D objects. The values read in will be...
8
by: Ray D. | last post by:
I'm trying to write a C function to compute the compressed row storage (CRS) vectors of a 2-d matrix. This is used primarily for increasing computing efficiency of matrices whose main elements are...
4
by: attackwarningred | last post by:
Dear All, Hello! I've just started to use Python and its a lovely language! I've previously programmed in Fortran 95 and have just began to use numpy. I'm having a few problems with arrays in...
14
by: stevenruiz | last post by:
Hello All My question mainly is how to use/reference Double Pointers? I am currently trying to understand what the meaning of a 'vector of pointers' means also? What I am trying to do is take...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.