473,372 Members | 883 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,372 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 2826
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.