Redim Array

H

Hege M

Hi!
I have a multidimensional array liste() which I declare dynamic.
But when I try to redimension it it wan't work.
ReDim list(1,7) works OK, but Redim Preserve liste(1,7) works the first time
around but then I get error.

I would like to be able to set the array just the size I need and I read
records from a textfiloe into the array så I don't know the size when I start.

How can I put this right?
 
C

Chuck

You're spelling the array name differently ("list" vs "liste"). Assuming
that you're spelling the array name correctly in your code, you need to post
your problem code and tell us what specific error message you're getting.
 
H

Hege M

Hi!
Thank's for trying to help me.

The code are as follows:
Public liste() As String (in the general declaration area)

The code that goes wrong is this:
Dim n As Integer
Erase liste()
Open "C:\Multiconsult\Adresser.txt" For Input As 1
n = 0
While Not EOF(1)
ReDim Preserve liste(n, 7)
Input #1, liste(n, 0), liste(n, 1), liste(n, 2), liste(n, 3),
liste(n, 4), liste(n, 5), liste(n, 6), liste(n, 7)
n = n + 1
Wend
Close 1

The first time around when n=0 goes OK, but then I get:
Run time error '9'.
Subscript out of range

Hege
Chuck skrev:
 
J

Jean-Guy Marcil

Hege M was telling us:
Hege M nous racontait que :
Hi!
Thank's for trying to help me.

The code are as follows:
Public liste() As String (in the general declaration area)

The code that goes wrong is this:
Dim n As Integer
Erase liste()
Open "C:\Multiconsult\Adresser.txt" For Input As 1
n = 0
While Not EOF(1)
ReDim Preserve liste(n, 7)
Input #1, liste(n, 0), liste(n, 1), liste(n, 2), liste(n, 3),
liste(n, 4), liste(n, 5), liste(n, 6), liste(n, 7)
n = n + 1
Wend
Close 1

The first time around when n=0 goes OK, but then I get:
Run time error '9'.
Subscript out of range

You can only ReDim Preserve on the last dimension.
You have to transpose your code so that you have something like
ReDim Preserve liste(7, n)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Chuck

You can only change the last dimension in the array. You're trying to change
the first. Flip your array around: Redim preserve liste(7, n) and change the
rest of your code accordingly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top