[RETO] Recortar cadena.

Iniciado por Psyke1, 21 Octubre 2011, 10:18 AM

0 Miembros y 1 Visitante están viendo este tema.

Psyke1

#10
Cita de: BlackZeroX (Astaroth) en 21 Octubre 2011, 19:27 PM
Cita de: Psyke1 en 21 Octubre 2011, 10:18 AM
Vale todo el más rápido gana.
>:D

>:D

Código (vb) [Seleccionar]
Option Explicit
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Long)
Private Declare Function SysAllocStringByteLen Lib "oleaut32.dll" (ByVal oleStr As Long, ByVal BLen As Long) As Long

Public Static Function RemoveStr_Psyke1(ByVal sText As String, ByVal lPosIni As Long, ByVal lLen As Long) As String
Dim lLenB                                   As Long
Dim lpString                                As Long

   lLenB = LenB(sText)
   If lLenB Then
       If (lPosIni Or lLen) And &H80000000 Then Exit Function
       
       lLen = (lLen + lLen)
       lPosIni = (lPosIni + lPosIni)
       
       If (lPosIni + lLen) = lLenB Then lLen = lLenB

       If (lLen = lLenB) And (lPosIni = 0&) Then
           RemoveStr_Psyke1 = sText
           Exit Function
       End If

       lpString = StrPtr(sText)
       
       RtlMoveMemory (lpString + lPosIni), (lpString + lPosIni + lLen), (lLenB - lPosIni + lLen)
       RtlMoveMemory VarPtr(RemoveStr_Psyke1), VarPtr(SysAllocStringByteLen(lpString, lLenB - lLen)), 4&
   End If
End Function

Private Sub Form_Load()
   MsgBox RemoveStr_Psyke1("hola amigo 123456789", 4, 6)
End Sub


DoEvents! :P

BlackZeroX

#11
@Psyke1

Tu funcion Crashea!¡.

Código (vb) [Seleccionar]


    Debug.Print RemoveStr_Psyke1("BlackZeroX", -1, 4), Len(RemoveStr_Psyke1("BlackZeroX", -1, 4))
    Debug.Print RemoveStr_Psyke1("BlackZeroX", 9, 4), Len(RemoveStr_Psyke1("BlackZeroX", 9, 4))
    Debug.Print RemoveStr_Psyke1("BlackZeroX", 0, -4), Len(RemoveStr_Psyke1("BlackZeroX", 0, -4))
    Debug.Print RemoveStr_Psyke1("BlackZeroX", 1, 4), Len(RemoveStr_Psyke1("BlackZeroX", 1, 4))
    Debug.Print RemoveStr_Psyke1("BlackZeroX", 0, 4), Len(RemoveStr_Psyke1("BlackZeroX", 0, 4))
    Debug.Print RemoveStr_Psyke1("BlackZeroX", 0, 400), Len(RemoveStr_Psyke1("BlackZeroX", 0, 400))



Dulces Lunas!¡.
The Dark Shadow is my passion.

Psyke1

A mí no me crashea con más de tres llamadas... :rolleyes:
Prueba a quitar el Static por si acaso...

DoEvents! :P

BlackZeroX

#13
Cita de: Psyke1 en 23 Octubre 2011, 21:50 PM
A mí no me crashea con más de tres llamadas... :rolleyes:

... Nada tiene que ver static (Que por cierto static para procesos carece de la funcionalidad habitual de llamada a funcion/proceso sin instanciar la clase y por ende esta demas en una funcion miembro static para variables muy diferente a static para miembros de clases y TODO esto deberia ser lo mismo para vb6, pero no es asi).

* El unico uso que le preveo es una Generalizacion de la declaracion static para las declaraciones internas para EVITAR que se autodestruyan las variables.

Mira este codigo:

Código (Vb) [Seleccionar]


Option Explicit

Private Sub Form_Load()
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
    Debug.Print holaNoStatic, holaStatic
End Sub

Public Function holaNoStatic() As String
Dim a As Integer
    Debug.Print "[a=" & VarPtr(a) & "]",
    holaNoStatic = a
    a = a + 1
End Function

Public Static Function holaStatic() As String
Dim a As Integer
    Debug.Print "[a=" & VarPtr(a) & "]"
    holaStatic = a
    a = a + 1
End Function



Revisa tu funcion con las 6 pruebas que deje en el anterior post.

Dulces Lunas!¡.
The Dark Shadow is my passion.

BlackZeroX

Cuando se Hacen los Test?

Dulces Lunas!¡.
The Dark Shadow is my passion.