April 27, 2024, 05:02:29 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


ReDIM Substitute?

Started by tbohon, January 08, 2007, 11:30:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tbohon

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
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

Ionic Wind Support Team

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?
Ionic Wind Support Team

tbohon

The array size will remain the same - just need to clear them (text labels) between records.

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

Ionic Wind Support Team

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)

Ionic Wind Support Team

REDEBOLT

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
Regards,
Bob

J B Wood (Zumwalt)

Although haven't tried this...


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


Ionic Wind Support Team

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.
Ionic Wind Support Team

REDEBOLT

Thank you all for your help.
The solution is very straight-forward.

Regards,
Bob
Regards,
Bob

tbohon

Gee, my simple little question leads to all sorts of useful information.

Thanks, guys!!!

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)