Xojo Conferences
XDCMay2019MiamiUSA

ReDim and Zeroing an array (Real Studio getting started Mailinglist archive)

Back to the thread list
Previous thread: Resizing a Scrollbar
Next thread: Mac file


RB Database   -   tom.russell transport.alstom.com
  ReDim and Zeroing an array   -   Artly There
   Re: ReDim and Zeroing an array   -   Phil M
   Re: ReDim and Zeroing an array   -   Joseph J. Strout
    Re: ReDim and Zeroing an array   -   Artly There
     Re: ReDim and Zeroing an array   -   Joseph J. Strout
      Re: ReDim and Zeroing an array   -   Artly There
       Re: ReDim and Zeroing an array   -   Joseph J. Strout

ReDim and Zeroing an array
Date: 11.02.05 19:09 (Fri, 11 Feb 2005 13:09:40 -0500)
From: Artly There
Q:

1. Given an array of class records (or any array) keeping the same
number of elements around, what's the best (and fastest) way in RB to
zero out existing elements before you refill the bucket again ? In FB
I could use Def Blockfill or a blockmove. Not sure what to use here,
unless the below is the ticket.

2. What's the best way to just clear out an entire array so you can
start from scratch and be assured that as it expands, you have clean
data? ReDim back to (0) elements? And then ReDim back up? I assume
that after such a downsizing and re-upsizing that all the new elements
(class instances of some record) in that case of going back up will be
zero'd , and that I'll again have to make each instance of particular
elements again with New?

(thanks)

For instance (ha) :) in some Property in some class:

Array(-1) as <class> BigRec

Somewhere after a file load where data is coming in...

ReDim Array(maxElements)

During the operation...

Array(index) = New BigRec
Go fill and play with Array(index)

Array(index+1) = New BigRec and so on.. go play there...

... on up to Array(maxElements)

Once done with this Array(maxElements)...How to clear and 'reset'...

I'm Guessing:

ReDim Array(0)

Now...

ReDim Array(NewMaxElements) // for a different data file content
situation

Array(0) = New BigRec
Go fill and play with Array(0)

Array(1) = New BigRec and so on..
Go fill and play with Array(1)

I have this understanding correct?

Robert Covington

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: ReDim and Zeroing an array
Date: 11.02.05 19:59 (Fri, 11 Feb 2005 10:59:51 -0800)
From: Phil M
On Feb 11, 2005, at 10:09 AM, Artly There wrote:

> What's the best way to just clear out an entire array so you can start
> from scratch and be assured that as it expands, you have clean data?
> ReDim back to (0) elements? And then ReDim back up? I assume that
> after such a downsizing and re-upsizing that all the new elements
> (class instances of some record) in that case of going back up will be
> zero'd , and that I'll again have to make each instance of particular
> elements again with New?

Yes, but you would Redim the array to (-1). If you Redim it to (0)
then there is still one element remaining.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: ReDim and Zeroing an array
Date: 11.02.05 20:09 (Fri, 11 Feb 2005 13:09:49 -0600)
From: Joseph J. Strout
At 1:09 PM -0500 2/11/05, Artly There wrote:

>1. Given an array of class records (or any array) keeping the same
>number of elements around, what's the best (and fastest) way in RB
>to zero out existing elements before you refill the bucket again ?

That's a good question. The two obvious approaches are (1) use a
simple for/next loop, and (2) Redim the array to -1, then Redim it
back to its proper size. I can't guess which is faster.

>2. What's the best way to just clear out an entire array so you can
>start from scratch and be assured that as it expands, you have clean
>data? ReDim back to (0) elements?

Actually, I'd Redim it to -1.

> And then ReDim back up?

Well, that depends on what you're doing. But in most cases it's
easier to just .Append new elements as you go. (Don't worry, this
does not resize the array every time you call it.)

Best,
- Joe

Re: ReDim and Zeroing an array
Date: 11.02.05 22:55 (Fri, 11 Feb 2005 16:55:51 -0500)
From: Artly There

On Friday, February 11, 2005, at 02:09 PM, Joseph J. Strout wrote:
>> 1. Given an array of class records (or any array) keeping the same
>> number of elements around, what's the best (and fastest) way in RB to
>> zero out existing elements before you refill the bucket again ?
>
> That's a good question. The two obvious approaches are (1) use a
> simple for/next loop, and (2) Redim the array to -1, then Redim it
> back to its proper size. I can't guess which is faster.

It seems like given the number of fields in this case that the latter
is the simpler approach. I don't mind a loop otherwise.

>> 2. What's the best way to just clear out an entire array so you can
>> start from scratch and be assured that as it expands, you have clean
>> data? ReDim back to (0) elements?
>
> Actually, I'd Redim it to -1.

Yes. And thanks Phil for noting same. I meant ReDim the array back to (
0 ) elements as in none remaining after a -1. RB's array helpers are
what I needed for a 3D app I was working on ages ago...would have made
that a lot easier. (Insert, append, remove , etc)

>> And then ReDim back up?

> Well, that depends on what you're doing. But in most cases it's
> easier to just .Append new elements as you go. (Don't worry, this
> does not resize the array every time you call it.)

That should work out ok, as I can append on a utility record that I'm
working with as I go.

Thanks for the clarifications.

Robert

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: ReDim and Zeroing an array
Date: 11.02.05 23:16 (Fri, 11 Feb 2005 16:16:34 -0600)
From: Joseph J. Strout
At 4:55 PM -0500 2/11/05, Artly There wrote:

>>That's a good question. The two obvious approaches are (1) use a
>>simple for/next loop, and (2) Redim the array to -1, then Redim it
>>back to its proper size. I can't guess which is faster.
>
>It seems like given the number of fields in this case that the
>latter is the simpler approach. I don't mind a loop otherwise.

The number of fields is irrelevant; here's the loop:

for i = UBound(myArray) downTo 0
myArray(i) = nil
next

As you can see, it makes no difference what the objects in myArray
are. (This is to get an effect equivalent to emptying and resizing
the array.)

Best,
- Joe

Re: ReDim and Zeroing an array
Date: 12.02.05 00:53 (Fri, 11 Feb 2005 18:53:59 -0500)
From: Artly There

On Friday, February 11, 2005, at 05:16 PM, Joseph J. Strout wrote:

> At 4:55 PM -0500 2/11/05, Artly There wrote:
>
>>> That's a good question. The two obvious approaches are (1) use a
>>> simple for/next loop, and (2) Redim the array to -1, then Redim it
>>> back to its proper size. I can't guess which is faster.
>>
>> It seems like given the number of fields in this case that the latter
>> is the simpler approach. I don't mind a loop otherwise.
>
> The number of fields is irrelevant; here's the loop:
>
> for i = UBound(myArray) downTo 0
> myArray(i) = nil
> next
>
> As you can see, it makes no difference what the objects in myArray
> are. (This is to get an effect equivalent to emptying and resizing
> the array.)
>
> Best,
> - Joe

That's nice to know.

I thought about such an approach after I posted my last reply, and then
tried it. But it didn't work.

What does make a difference is

CBlock(0) = 0

;) That generates a type mismatch.

But :

CBlock(0) = nil as you have it works a spiffy.

I always thought nil was 0...is Nil keyword in RB doing more behind
the scenes than it would seem ?

Robert

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

Re: ReDim and Zeroing an array
Date: 12.02.05 05:57 (Fri, 11 Feb 2005 22:57:52 -0600)
From: Joseph J. Strout
At 6:53 PM -0500 2/11/05, Artly There wrote:

>CBlock(0) = 0
>
> ;) That generates a type mismatch.
>
>But :
>
>CBlock(0) = nil as you have it works a spiffy.
>
>I always thought nil was 0...

Nope, no more than 0 is black or black is nil.

>is Nil keyword in RB doing more behind the scenes than it would seem ?

No, they're just different types. Nil is of type Object; 0 is type Integer.

Best,
- Joe