Foros del Web » Programando para Internet » ASP Clásico »

matrices de dos dimensiones

Estas en el tema de matrices de dos dimensiones en el foro de ASP Clásico en Foros del Web. Hola grupo! Tengo un pequeño problema (grande la verdad, enorme, diria yo) y es que en mi programa manejo una matriz de dos dimensiones, y ...
  #1 (permalink)  
Antiguo 05/06/2002, 13:42
 
Fecha de Ingreso: abril-2002
Mensajes: 11
Antigüedad: 22 años, 2 meses
Puntos: 0
matrices de dos dimensiones

Hola grupo!

Tengo un pequeño problema (grande la verdad, enorme, diria yo) y es que en mi programa manejo una matriz de dos dimensiones, y es dinamica para que pueda redimensionarla si lo necesito. Yo hago lo siguiente:

Dim mimatriz()
....
Redim mimatriz(50,5)
....
if ubound(mimatriz)=contador then
Redim mimatriz(50+contador,5)
end if

El caso es que funciona asi como está. Pero yo necesito que se conserve lo que tenia la matriz anteriormente asi que utilizo la clausula preserve dentro del if. Y es aqui donde falla. Si le pongo
Redim preserve mimatriz(50+contador,5)
no funciona.

¿Podria alguien decirme si es que esta clausula solo funciona para las matrices de una dimension?
y ¿hay algo que pueda hacer para redimensionar sin perder lo ya escrito en la matriz?

Gracias a todos, por adelantado.
  #2 (permalink)  
Antiguo 05/06/2002, 13:55
Avatar de urjose  
Fecha de Ingreso: diciembre-2001
Mensajes: 5.286
Antigüedad: 22 años, 5 meses
Puntos: 1
Re: matrices de dos dimensiones

Cita:
STATEMENT: ReDim

--------------------------------------------------------------------------------
ReDim

The ReDim statement allows you to formally declare, and to later redeclare as many times as you need, the size (and hence the memory space allocation) for a dynamic array that was originally declared using either a Dim, Private or Public statement.

The first time you use ReDim to declare an array, you can create either a single or a multiple dimension array. However, after you have set the number of the dimensions, you cannot later go back and change the number of the dimensions. Also, once you have created a multi-dimension array, you can only redeclare the size of the last element.

If you make the array bigger, you can use the keyword Preserve to protect all of the existing elements. If you make the array smaller, you will lose part of the array elements even if you use Preserve. Do not use Preserve the first time that you ReDim an array since it will prohibit setting multiple dimensions.

In this example, we declare myarray() to have a single dimensions and then resize the element. When we resize from 999 down to 9, we lose the data in the other 990 elements.

Code:
<% Dim myarray() %>
<% ReDim myarray(5) %>
<% ReDim Preserve myarray(999) %>
<% ReDim Preserve myarray(9) %>

In this example, we declare myarray() to have three dimensions and then resize the last element. When we resize the last element from 999 down to 9, we lose the data in the other 990 elements.

Code:
<% Dim myarray() %>
<% ReDim myarray(20, 10, 99) %>
<% ReDim Preserve myarray(20, 10, 999) %>
<% ReDim Preserve myarray(20, 10, 9) %>


<center><a href="http://www.forosdelweb.com/comment_usr.asp?usr=urjose"><img border="0" src="http://pcmasmas.com.ar/foro/images/avatars/043.gif"></a></center>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:17.