
still having a problem with redim
I posted this question yesterday but the help I was given didn't work. Thanks anyway! Maybe someone else could find the problem. I've got 2 arrays. The first one has 32 positions. There essentially could be many positions without any data. So, my 2nd array iterates through the 1st one and whenever it finds data, it sticks it into it's next available slot. So now my 2nd array has the same data as the 1st, except that all the data is appearing as one after the next instead of having any empty elements between data. Finally, I iterate through my 2nd array to find out how many positions hold data and then I try to redim my array with this counter variable. However, I'm getting an error that says "This array is fixed or temporarily locked" when I try to redim preserve it. Any ideas? Thanks.<BR><BR>dim printedOptions(32)<BR><BR>for i = 0 to ubound(options)<BR> if options(i) <> "" then<BR> for j = 0 to ubound(printedOptions)<BR> if printedOptions(j) = "" then<BR> printedOptions(j) = options(i)<BR> exit for<BR> end if<BR> next<BR> end if<BR>next<BR><BR>j = 0<BR>for i = 0 to ubound(printedOptions)<BR> if printedOptions(i) <> "" then<BR> j = j + 1<BR> end if<BR>next<BR><BR>ReDim Preserve printedOptions(j)

That's because you've programmed it that
...<BR><BR>you are sticking option(i) in the first printedOptions(j) that is blank.<BR><BR>do both arrays have the same number of elements?

RE: still having a problem with redim
dim printedOptions(),i, j<BR>redim printedOptions(ubound(options))<BR><BR>for i = 0 to ubound(options)<BR>If options(i)<>"" Then<BR>printedOptions(j)=options(i)<BR>j=j+1<BR>E nd If<BR>next<BR>redim preserve printedOptions(j1)<BR>

that's what I was trying to do
Yes, they both have 32 elements initially. Sorry, I dimmed my options array a little higher up in the page. They are both dimmed as options(32) and printedOptions(32). I want to put the data from my options in the first available slot in my printedOptions arrays so that there are no empty slots between the data. That's why you see it that way. Any ideas?

Confused then?
What is the problem then? Sorry, not following your desired goal?

RE: still having a problem with redim
When you initially declare the array you are declaring it fixed size not dynamic ( dim printedOptions(32) ), to declare so you can resize it, do it like this :<BR><BR>Dim printedOptions()<BR><BR>ReDim printedOptions(32)<BR><BR>You can the resize it as many times as you wish with or without the preserve keyword.<BR><BR>MikeD<BR><BR>

perfect....but what happened?
Thanks! That worked perfectly. But I'm unclear on what you changed. I like it because the code is a lot more compact, but what exactly did you change? I tried following the code and it seems to be doing the same thing mine did, just in a shorter amount of time, so I'm a little stumped as to what was originally wrong with mine that gave me that error. Thanks again.

I did not know that:)
Thanks Mike, that makes sense!

RE: perfect....but what happened?
You needed to start your code with <BR>dim printedOptions()<BR>redim printedOptions(32) 'or use ubound(options) in place of the 32<BR><BR>can only redim a dynamic array ie dimmed without dimensions.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

