elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [Solucionado] Como Desbloquear un Array...
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Solucionado] Como Desbloquear un Array...  (Leído 3,775 veces)
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
[Solucionado] Como Desbloquear un Array...
« en: 10 Octubre 2010, 03:46 am »

.
Alquien sabe como solucionar esto?...

Me da el error 10: La matriz está fija o temporalmente bloqueada

Código
  1.  
  2. Option Explicit
  3. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
  4.        (Destination As Any, Source As Any, ByVal Length As Long)
  5. Private Const InvalidValueArray = -1
  6.  
  7. Private Sub Form_Load()
  8. Dim arr()          As Long
  9.    redim arr(0 to 5)
  10.    arr(0) = 12
  11.    arr(1) = 13
  12.    arr(2) = 14
  13.    arr(3) = 15
  14.    arr(4) = 16
  15.    arr(5) = 17
  16.    RemoveInArrayLong 4, arr
  17. End Sub
  18.  
  19. Private Function RemoveInArrayLong(ByVal Index&, ByRef ThisArray() As Long) As Boolean
  20. Dim LenArray        As Long
  21. Dim tArray()        As Long
  22.  
  23.    If Not (Not ThisArray) = InvalidValueArray Then
  24.        LenArray = UBound(ThisArray) - LBound(ThisArray)
  25.        If LenArray - 1 >= 0 Then
  26.            If LenArray = Index& Then
  27.                ReDim Preserve ThisArray(LBound(ThisArray) To (UBound(ThisArray) - 1))
  28.            Else
  29.                ReDim tArray(LenArray - 1)
  30.                If Index > 0 Then
  31.                    Call CopyMemory(ByVal VarPtr(tArray(LBound(tArray))), ByVal VarPtr(ThisArray(LBound(ThisArray))), 4 * Index&)
  32.                End If
  33.                Call CopyMemory(ByVal VarPtr(tArray(Index)), ByVal VarPtr(ThisArray(Index& + 1)), 4 * (LenArray - Index&))
  34.                ReDim ThisArray&(LenArray - 1)
  35.                Call CopyMemory(ByVal VarPtr(ThisArray(LBound(ThisArray))), (tArray(LBound(tArray))), 4 * LenArray)
  36.                Erase tArray
  37.            End If
  38.            RemoveInArrayLong = True
  39.        Else
  40.            Erase ThisArray
  41.            RemoveInArrayLong = False
  42.        End If
  43.    End If
  44. End Function
  45.  
  46.  

Edito
.
Ojo tiene que ser via parametro el Array...

Dulces Lunas!¡.


« Última modificación: 10 Octubre 2010, 09:24 am por BlackZeroX » En línea

The Dark Shadow is my passion.
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: Como Desbloquear un Array...
« Respuesta #1 en: 10 Octubre 2010, 08:02 am »

Hola, el error 10 es porque ya dimensionaste antes el array, ej:

Esto tendrías que poner:

Código
  1. Dim arr()  As Long
  2.  
  3. ReDim arr(0 To 5)
  4.  
  5. arr(0) = 12
  6. arr(1) = 13
  7. arr(2) = 14
  8. arr(3) = 15
  9. arr(4) = 16
  10. arr(5) = 17
  11.  

Pero tu codigo sigue funcionando mal :(.

Asi que lo hice a mano, tal vez lo puedas mejorar o arreglar,

Código
  1. Private Sub Form_Load()
  2. Dim arr()  As Long
  3.  
  4. ReDim arr(0 To 5)
  5.    arr(0) = 12
  6.    arr(1) = 13
  7.    arr(2) = 14
  8.    arr(3) = 15
  9.    arr(4) = 16
  10.    arr(5) = 17
  11.    NewRemoveInArrayLong 4, arr
  12. End Sub
  13.  
  14. Private Function NewRemoveInArrayLong(ByVal Index&, ByRef ThisArray() As Long) As Boolean
  15. Dim tArray() As Long
  16. Dim i As Integer
  17.  
  18. If Not IsArray(ThisArray) Or Index& = -1 Then
  19.    NewRemoveInArrayLong = False
  20.    Exit Function
  21. End If
  22.  
  23. If Index& = UBound(ThisArray) Then
  24.    ReDim Preserve ThisArray(LBound(ThisArray) To (UBound(ThisArray) - 1))
  25.  
  26.    NewRemoveInArrayLong = True
  27.    Exit Function
  28. Else
  29.    ReDim tArray(LBound(ThisArray) To (UBound(ThisArray) - 1))
  30.    For i = LBound(ThisArray) To UBound(ThisArray)
  31.        If i < Index& Then
  32.            tArray(i) = ThisArray(i)
  33.        ElseIf i > Index& Then
  34.            tArray(i - 1) = ThisArray(i)
  35.        End If
  36.    Next i
  37.    ReDim ThisArray(LBound(tArray) To UBound(tArray))
  38.    ThisArray = tArray
  39.    Erase tArray
  40.  
  41.    NewRemoveInArrayLong = True
  42.    Exit Function
  43. End If
  44. NewRemoveInArrayLong = False
  45. End Function
  46.  
  47.  

Y muchas gracias por ayudarme en el otro post  ;-), igualmente tuve una nueva duda, si puedes héchale un vistazo.  :laugh:


En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Como Desbloquear un Array...
« Respuesta #2 en: 10 Octubre 2010, 09:00 am »

.
@Miseryk

No me Sirven los For Next son tardados y lo que requiero es Velocidad a punta de derrame..

Gracias... miura ahorita ando con punteros y estructuras de variables... ya di con el problema de hecho esto me soluciona MUCHAS cosas anteriores... enseguida publico la solucion xD

Dulces Lunas!¡
« Última modificación: 10 Octubre 2010, 09:12 am por BlackZeroX » En línea

The Dark Shadow is my passion.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Como Desbloquear un Array...
« Respuesta #3 en: 10 Octubre 2010, 09:24 am »

.
Bien aquí esta la cosa... lo lamento pero estaba algo atontado con algunas cosas xP.

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
  5.        (Destination As Any, Source As Any, ByVal Length As Long)
  6. Private Const InvalidValueArray = -1
  7.  
  8. Private Sub Form_Load()
  9. Dim Arr()           As Long
  10. Dim a               As Long
  11.    For a = 0 To 99999  '   //  Es solo para verificar si hay Crash
  12.        DoEvents
  13.        ReDim Arr(0 To 5)
  14.        Arr(0) = 12
  15.        Arr(1) = 13
  16.        Arr(2) = 14
  17.        Arr(3) = 15
  18.        Arr(4) = 16
  19.        Arr(5) = 17
  20.        RemoveInArrayLong 3, Arr
  21.        Debug.Print a
  22.    Next a
  23. End Sub
  24.  
  25. Private Function RemoveInArrayLong(ByVal Index&, ByRef ThisArray() As Long) As Boolean
  26. Dim lng_Old         As Long
  27. Dim lng_LBound      As Long
  28. Dim lng_UBound      As Long
  29. Dim lng_LenArray    As Long
  30. Dim lng_lenToCopy   As Long
  31. Dim Arrlng_Old()    As Long
  32.  
  33.    If Not (Not ThisArray) = InvalidValueArray Then
  34.        lng_LBound = LBound(ThisArray)
  35.        lng_UBound = UBound(ThisArray)
  36.        If Index& <= lng_UBound Then
  37.            lng_LenArray = lng_UBound
  38.            If lng_LBound = 0 Then lng_LenArray = lng_LenArray + 1
  39.            If lng_LenArray > 1 Then
  40.                lng_lenToCopy = lng_UBound - Index& - 1
  41.                If lng_LBound = 0 Then lng_lenToCopy = lng_lenToCopy + 1
  42.                If lng_UBound - Index& - 1 >= 0 Then
  43.                    ReDim Arrlng_Old(lng_LBound To lng_UBound - Index& - 1)
  44.                    Call CopyMemory(ByVal VarPtr(Arrlng_Old(lng_LBound)), _
  45.                                    ByVal VarPtr(ThisArray(Index& + 1)), 4 * lng_lenToCopy)
  46.                    Call CopyMemory(ByVal VarPtr(ThisArray(Index&)), _
  47.                                    ByVal VarPtr(Arrlng_Old(lng_LBound)), 4 * lng_lenToCopy)
  48.                End If
  49.                ReDim Preserve ThisArray(lng_LBound To lng_UBound - 1)
  50.                RemoveInArrayLong = True     '   // Estos son Returns que uso yo... en si son True
  51.            Else
  52.                Erase ThisArray
  53.                RemoveInArrayLong = False    '   // Estos son Returns que uso yo... en si son True
  54.            End If
  55.        End If
  56.    End If
  57. End Function
  58.  
  59.  

Dulce Infierno Lunar!¡.
« Última modificación: 10 Octubre 2010, 09:34 am por BlackZeroX » En línea

The Dark Shadow is my passion.
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: [Solucionado] Como Desbloquear un Array...
« Respuesta #4 en: 10 Octubre 2010, 10:24 am »

BlackZeroX fijate que se puede eliminar sin utilizar el array temporal

Código:
Function RemoveInArrayLong(ByVal Index As Long, ByRef ThisArray() As Long) As Boolean
    Dim LenArray As Long
    LenArray = UBound(ThisArray)
    If Index < 0 Or Index > LenArray Then Exit Function
    If Not (Index = LenArray) Then
        Call CopyMemory(VarPtr(ThisArray(Index)), VarPtr(ThisArray(Index + 1)), (LenArray - Index) * 4)
    End If
    If LenArray - 1 >= 0 Then
        ReDim Preserve ThisArray(LenArray - 1)
        RemoveInArrayLong = True
    Else
        Erase ThisArray()
    End If
End Function
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [Solucionado] Como Desbloquear un Array...
« Respuesta #5 en: 10 Octubre 2010, 10:57 am »

.
Solo le faltaron los Byval en la linea del Copymemory.
.
Thank's... ando algo traumado ahorita son unas cosillas como esta... y andaba probando (Esto no lo sabia), por eso use Dos Arrays...

Código
  1.  
  2. Option Explicit
  3.  
  4. Enum tAlign
  5.    Align_Left = 0
  6.    Align_Center
  7.    Align_Right
  8. End Enum
  9.  
  10. Private Type RECTFila
  11.    Left                                    As Long
  12.    Top                                     As Long
  13.    'Right                                   As Long
  14.    Bottom                                  As Long
  15. End Type
  16.  
  17. Private Type tConfigItem
  18.    Text                                    As String
  19.    Tag                                     As String
  20.    Key                                     As String
  21.    ForeColor                               As Long
  22.    Bold                                    As Byte
  23.    Italic                                  As Byte
  24.    Underline                               As Byte
  25.    Aligh                                   As tAlign
  26. End Type
  27.  
  28. Private Type tConfigFilas                           '   //  Region General de las Filas.
  29.    ToolTip                                 As String
  30.    Tag                                     As String
  31. End Type
  32.  
  33. Private Type tFilas     '   //  Region General de las Filas.
  34.    Item                                    As tConfigItem
  35.    SubItems()                              As tConfigItem
  36.    ConfiguracionFila                       As tConfigFilas
  37.    Region                                  As RECTFila
  38. End Type
  39.  
  40. Dim Item(0 To 1)            As tFilas
  41.  
  42. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
  43.  
  44. Private Sub SwaptFilas(StructOrigen As tFilas, StructDest As tFilas)
  45. Dim lng_PtrOld()                            As Byte
  46. Dim ln_Bytes                                As Long
  47.    ln_Bytes = LenB(StructDest)
  48.    If ln_Bytes > 0 Then
  49.        ReDim LHold(1 To ln_Bytes)
  50.        CopyMemory LHold(0), ByVal VarPtr(StructOrigen), ln_Bytes
  51.        CopyMemory ByVal VarPtr(StructOrigen), ByVal VarPtr(StructDest), ln_Bytes
  52.        CopyMemory ByVal VarPtr(StructDest), LHold(0), ln_Bytes
  53.    End If
  54. End Sub
  55.  
  56. Private Sub Command1_Click()
  57.    'MsgBox LenB(Item(0))
  58.    With Item(0)
  59.        ReDim .SubItems(20)
  60.        MsgBox UBound(.SubItems)
  61.        .Item.Text = "Miguel Angel"
  62.        .Item.Tag = "Ortega Avila"
  63.    End With
  64.    Call SwaptFilas(Item(0), Item(1))
  65.    Debug.Print
  66.    With Item(1)
  67.        MsgBox UBound(.SubItems)
  68.        Debug.Print .Item.Text, .Item.Tag, UBound(.SubItems)
  69.    End With
  70.    With Item(0)
  71.        MsgBox UBound(.SubItems)
  72.        Debug.Print .Item.Text, .Item.Tag, UBound(.SubItems)
  73.    End With
  74. End Sub
  75.  
  76.  

Dulce Infierno Lunar!¡.
En línea

The Dark Shadow is my passion.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Solucionado] Manejo de Array's
Programación Visual Basic
agus0 3 2,085 Último mensaje 14 Enero 2011, 15:36 pm
por agus0
[SOLUCIONADO] Pasar array como parámetro.
Java
NetJava 3 22,917 Último mensaje 15 Febrero 2011, 21:55 pm
por Debci
[SOLUCIONADO] Programa Sencillo: Representación de un Array
Programación C/C++
LaLakers94 6 2,920 Último mensaje 5 Mayo 2014, 17:49 pm
por rir3760
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines