PDA

Click to See Complete Forum and Search --> : Please, Help! I'm trying something...


Arie
Jun 17th, 2001, 05:09 AM
Hi!

I have a problem!
This file has a simple project that calls an A string.
The string is declared like this: Private A() as String.
When I want to use it I do:
ReDim A(1)
A(1) = "Arie"
Print A(1)

Goes well! But then, when I try this:
ReDim A(2)
A(2) = "Ball"

And Then...

Print A(1)
Print A(2)

The Value of A(1) is gone!!!

What's wrong?!?

Tell me,
Please,
Arie.

Fox
Jun 17th, 2001, 07:04 AM
Use "Redim Preserve .." and it will work *hehehe*

Arie
Jun 18th, 2001, 02:09 AM
Ok, that works, but now...

I have another problem!
I had other variables like:

Type PL
X as Integer
Y as Integer
.
.
.
End type
Public Player As PL


Now the Player.X is gone. why?
All the other are OK.
Did I do something with the Preserve?
How do I use it? Where should I put it?
Help, Fox!

Arie.

Fox
Jun 18th, 2001, 04:26 AM
The Preserve tells ReDim to keep the values in the array youre modifying. It only works for the last dimension of the array, meaning:


Dim Temp()

ReDim Temp(10) 'Create empty 1D array
ReDim Preserve Temp(20) 'Change size of last dimension

ReDim Temp(10, 10) 'Create empty 2D array
ReDim Preserve Temp(10, 20) 'Change size of last dimension
ReDim Preserve Temp(20, 20) 'Change size of more dimensions - won't work

Erase Temp 'Release memory




About your type: Should work, the errer must be somewhere else..

Arie
Jun 18th, 2001, 07:50 AM
Ok... but,...
how this is related with my Type ?
Why my Type values are gone?
All worked until I put this Preserve thing...
What's wrong?

Arie.

Fox
Jun 18th, 2001, 08:06 AM
What do you mean'its gone' ?

If it's not in the properties you may have done a mistake somewhere.. try compiling it.

Arie
Jun 21st, 2001, 02:43 PM
Thank you very much, Fox!
You were very helpful. Thanx!!!

Arie.