IonicWind Software

IWBasic => General Questions => Topic started by: tbohon on January 08, 2007, 11:30:58 AM

Title: ReDIM Substitute?
Post by: tbohon on January 08, 2007, 11:30:58 AM
Does anyone have a quick (translation:  fast) substitute routine in EBasic for the redim command?  I'm working on a large parsing project and want to (constantly) reuse a working array - but it has to be totally cleaned out between each use.  Yes, I'm aware I could write a short for loop to do it - just wondering if there are any other options.

Thanks in advance.

Tom
Title: Re: ReDIM Substitute?
Post by: Ionic Wind Support Team on January 08, 2007, 11:32:25 AM
Do you just want to set the elements of an existing array to zero?  Or are you trying to change the size of an array?
Title: Re: ReDIM Substitute?
Post by: tbohon on January 08, 2007, 01:33:06 PM
The array size will remain the same - just need to clear them (text labels) between records.

Tom
Title: Re: ReDIM Substitute?
Post by: Ionic Wind Support Team on January 08, 2007, 01:46:59 PM
DECLARE IMPORT,ZeroMemory ALIAS RtlZeroMemory( POINTER pvoid,INT length),INT

def a[10] as string
def d[100] as double

//ZeroMemory(array, elements * size)
ZeroMemory(a, 10 * 255)
ZeroMemory(d, 100 * 8)

Title: Re: ReDIM Substitute?
Post by: REDEBOLT on January 08, 2007, 04:07:12 PM
Quote from: Paul Turley on January 08, 2007, 11:32:25 AM
Do you just want to set the elements of an existing array to zero?  Or are you trying to change the size of an array?
Ok.  Suppose that I have an array that "grows."  I want to add more rows to an array while preserving the current contents.  Can I do this without delclaring a new array and copying the old array into it?

Suppose I don't know the array size untill run time.  For example, I want to parse a CSV file with an unknown number of fields until I read it.  Would this be done with "new" and using pointers?

Regards,
Bob
Title: Re: ReDIM Substitute?
Post by: J B Wood (Zumwalt) on January 08, 2007, 04:22:15 PM
Although haven't tried this...


def a[] as string
// do stuff until you need the array
a[size] as string
ZeroMemroy(a,10*255)

Title: Re: ReDIM Substitute?
Post by: Ionic Wind Support Team on January 08, 2007, 04:38:38 PM
You have to use NEW and a pointer if you want to have an array at runtime.  As explained in another thread, arrays that are defined like:

def a[100] as INT

Are not allocated, they are reserved in memory (the process address space) by the OS when the executable is loaded.  It is a fixed size and cannot be changed once compiled.  Using allocated arrays is not difficult though:

pointer p
p = new(INT, size)
#p[index] = value
print #p[index]
delete p

To change the size of the array you have two choices.  Use GlobalRealloc from the Windows API or allocate a second array the new size and copy the old contents.

Paul.
Title: Re: ReDIM Substitute?
Post by: REDEBOLT on January 08, 2007, 05:41:39 PM
Thank you all for your help.
The solution is very straight-forward.

Regards,
Bob
Title: Re: ReDIM Substitute?
Post by: tbohon on January 09, 2007, 06:11:44 AM
Gee, my simple little question leads to all sorts of useful information.

Thanks, guys!!!

Tom