ezyeric
09-30-2001, 01:22 PM
I have a Module in which I declared an array as so:
Global MsgArray(0,1) as String
Then in a Function in that Module I want to chage the ammount of elements in the Array so I have
Redim MsgArray(2,2)
But I get an error "Array already dimensioned"
Anyone know how I can still have that array global and change the dimensions in a function?
Thanx,
Eric
Volte
09-30-2001, 01:26 PM
Try
<pre><font color=blue>Option Explicit</font color=blue>
<font color=blue>Global</font color=blue> MsgArray() <font color=blue>As String</font color=blue>
<font color=blue>Private Sub</font color=blue> Form_Load()
Redim MsgArray(0, 1)
<font color=blue>End Sub</font color=blue>
<font color=blue>Private Sub</font color=blue> Command1_Click()
Redim MsgArray(2, 2)
<font color=blue>End Sub</font color=blue></pre>
Squirm
09-30-2001, 02:36 PM
You can only ever ReDim arrays that were declared with empty parenthesis () .....
Laurent
10-01-2001, 07:01 AM
just keep in mind that you you redim an array you lose all the data stored in it, or you use the preserve keyword
I'll be among the best soon, very soon!!!
anhmytran
10-01-2001, 07:40 AM
You can Redim only Un-Dimentional array with the word Reserve
to retain some data in it. It is easier to illustrate by example:
Public strArray() As String
In Form Load Event Procedure:
Redim strArray(0,1) As String ' that is 2 dimentions
strArray(0,0) = "A0"
strArray(0,1) = "B0"
In Form Activate Event Procedure:
Redim Preserve strArray(0,1,1) As String ' that is 3 dimentions
strArray(0,1,0) = "A1"
strArray(0,1,1) = "B1"
You still have the value "A0" and "B0"
But when you redim from the second dimention, you loose all.
for example
Redim Preserve strArray(0,5,1) As String ' change the 2nd dimentions
The principle is that: When Redim arrays with Preverve, you can
preserve only data in the dimentions of higher level (in the left)
AnhMy_Tran
KesleyK
10-01-2001, 09:01 PM
We just recently discussed this pretty well .
__________
HOOOaaaaa! Semper Fi!