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

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


  Mostrar Mensajes
Páginas: 1 ... 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [23] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 ... 128
221  Programación / Programación Visual Basic / [Src] IsInArray en: 9 Mayo 2011, 14:24 pm
Bueno, aquí os dejo esta sencilla función. :)
Su finalidad es devolver el Index de un Item que se encuentre en un array (acepta todo tipo de Arrays : String, Double, Long...), con la opción de devolver el primero que se encuentre en el array y con los parámetros lngStart y lngEnd podemos establecer límites en nuestra búsqueda.  :D
Para ordenarlo aconsejo usar esta maravillosa función que hizo mi amigo BlackZer0x :
http://goo.gl/RG4Bx

Código
  1. Option Explicit
  2. '======================================================================
  3. ' º Function  : IsInArray
  4. ' º Author    : Psyke1
  5. ' º Country   : Spain
  6. ' º Mail      : vbpsyke1@mixmail.com
  7. ' º Date      : 09/05/2011
  8. ' º Twitter   : http://twitter.com/#!/PsYkE1
  9. ' º Dedicated : BlackZer0x
  10. ' º Reference : http://goo.gl/RDQhK
  11. ' º Recommended Websites :
  12. '       http://foro.h-sec.org
  13. '       http://www.frogcheat.com.ar
  14. '       http://InfrAngeluX.Sytes.Net
  15. '======================================================================
  16. Public Static Function IsInArray&(varArr, _
  17.                                  varValue, _
  18.                                  Optional lngStart&, _
  19.                                  Optional lngEnd&, _
  20.                                  Optional bolFindFirst As Boolean, _
  21.                                  Optional bolIsSorted As Boolean)
  22. Dim lngLB&, lngUB&, Q&, C&
  23.    If (IsArray(varArr) = True) And (IsArray(varValue) = False) Then
  24.        lngLB = LBound(varArr)
  25.        lngUB = UBound(varArr)
  26.  
  27.        If Not IsMissing(lngStart) Then
  28.           If (lngStart > lngLB) And (lngStart < lngUB) Then lngLB = lngStart
  29.        End If
  30.        If Not IsMissing(lngEnd) Then
  31.           If (lngEnd > lngLB) And (lngEnd < lngUB) Then lngUB = lngEnd
  32.        End If
  33.  
  34.        If bolIsSorted Then
  35.            If varArr(lngLB) = varValue Then
  36.                IsInArray = lngLB
  37.                Exit Function
  38.            ElseIf varArr(lngUB) = varValue Then
  39.                If bolFindFirst Then
  40.                    Do While (varArr(lngUB) = varArr(lngUB - 1)) And (Q > lngLB)
  41.                        lngUB = lngUB - 1
  42.                    Loop
  43.                End If
  44.  
  45.                IsInArray = lngUB
  46.                Exit Function
  47.            End If
  48.  
  49.            If lngUB - lngLB < 2 Then GoTo NotFound
  50.            If (varArr(lngLB) > varValue) Or (varArr(lngUB) < varValue) Then GoTo NotFound
  51.  
  52.            C = 0
  53.            Do
  54.                Q = (lngUB + lngLB) \ 2
  55.                If C = Q Then GoTo NotFound
  56.  
  57.                If varArr(Q) > varValue Then
  58.                    lngUB = Q
  59.                ElseIf varArr(Q) < varValue Then
  60.                    lngLB = Q
  61.                    C = lngLB
  62.                Else
  63.                    If bolFindFirst Then
  64.                        Do While (varArr(Q) = varArr(Q - 1)) And (Q > lngLB)
  65.                            Q = Q - 1
  66.                        Loop
  67.                    End If
  68.  
  69.                    IsInArray = Q
  70.                    Exit Function
  71.                End If
  72.            Loop
  73.        Else
  74.            For Q = lngLB To lngUB
  75.                If varArr(Q) = varValue Then
  76.                    IsInArray = Q
  77.                    Exit Function
  78.                End If
  79.            Next Q
  80.  
  81.            GoTo NotFound
  82.        End If
  83.    End If
  84. Exit Function
  85.  
  86. NotFound:
  87.    IsInArray = -1
  88. End Function

Un ejemplo:
Código
  1. Option Explicit
  2.  
  3. Private Const strLine$ = "------------------------------"
  4.  
  5. Private Sub Form_Load()
  6. Dim L&(60), S(), Q&
  7.  
  8.    For Q = 0 To 60
  9.        L(Q) = Q * 2
  10.    Next Q
  11.  
  12.    Debug.Print strLine$, Time$, strLine$
  13.    Debug.Print IsInArray(L, 15)                '---> -1
  14.    Debug.Print IsInArray(L, 40)                '--->  20
  15.    Debug.Print IsInArray(L, 85)                '---> -1
  16.    Debug.Print IsInArray(L, 100)               '--->  50
  17.  
  18.    S = Array("abba", "acero", "karcrack", "sereno", "silencio", "tonto", "tonto", "tonto", "tonto", "zalme")
  19.  
  20.    Debug.Print strLine$
  21.    Debug.Print IsInArray(S, "zalme")           '--->  9
  22.    Debug.Print IsInArray(S, "zalme", , 4)      '---> -1
  23.    Debug.Print IsInArray(S, "mesa")            '---> -1
  24.    Debug.Print IsInArray(S, "besos")           '---> -1
  25.    Debug.Print IsInArray(S, "karcrack")        '--->  2
  26.    Debug.Print IsInArray(S, "karcrack", 3)     '---> -1
  27.    Debug.Print IsInArray(S, "tonto")           '--->  6
  28.    Debug.Print IsInArray(S, "tonto", , , True) '--->  5
  29. End Sub

Retorna:
Código:
------------------------------            18:59:54      ------------------------------
-1
 20
-1
 50
------------------------------
 9
-1
-1
-1
 2
-1
 6
 5



Si necesitamos especial velocidad y lo queremos para un tipo de variable en concreto, sólo hay que modificar un par de cosas. ;)
Aquí un ejemplo para buscar en un array Long, comparado con el código de BlackZer0x ( http://goo.gl/RDQhK ) :
Código:
Option Explicit
'// Compilado sin la comprobación de límites en los arrays xP

Private Sub Form_Load()
Dim L&(6000), Q&, t As New CTiming, y&
    
    If App.LogMode = 0 Then End
    
    For Q = 0 To 6000
        L(Q) = Q * 2
    Next Q
    
    Me.AutoRedraw = True
    
    t.Reset
    For Q = 1 To 1000
        IsInArray L, 15
        IsInArray L, 40
        IsInArray L, 2001
        IsInArray L, 5020
        IsInArray L, 12000
    Next Q
    Me.Print "IsInArray", , t.sElapsed
    
    t.Reset
    For Q = 1 To 1000
        ExitsInArrayNR 15, L, y
        ExitsInArrayNR 40, L, y
        ExitsInArrayNR 2001, L, y
        ExitsInArrayNR 5020, L, y
        ExitsInArrayNR 12000, L, y
    Next Q
    Me.Print "ExitsInArrayNR", t.sElapsed
End Sub

'// by Psyke1
Public Static Function IsInArray&(lngArr&(), lngValue&, Optional lngStart&, Optional lngEnd&, Optional bolFindFirst As Boolean)
Dim lngLB&, lngUB&, lngItem&, Q&, C&
    lngLB = LBound(lngArr)
    lngUB = UBound(lngArr)
    
    If Not IsMissing(lngStart) Then
       If (lngStart > lngLB) And (lngStart < lngUB) Then lngLB = lngStart
    End If
    If Not IsMissing(lngEnd) Then
       If (lngEnd > lngLB) And (lngEnd < lngUB) Then lngUB = lngEnd
    End If
    
    If lngArr(lngLB) = lngValue Then
        IsInArray = lngLB
        Exit Function
    ElseIf lngArr(lngUB) = lngValue Then
        If bolFindFirst Then
            Do While (lngArr(lngUB) = lngArr(lngUB - 1)) And (Q > lngLB)
                lngUB = lngUB - 1
            Loop
        End If
        IsInArray = lngUB
        Exit Function
    End If
    
    If lngUB - lngLB < 2 Then GoTo NotFound
    If (lngArr(lngLB) > lngValue) Or (lngArr(lngUB) < lngValue) Then GoTo NotFound
    
    C = 0
    Do
        Q = (lngUB + lngLB) \ 2
        If C = Q Then GoTo NotFound

        If lngArr(Q) > lngValue Then
            lngUB = Q
        ElseIf lngArr(Q) < lngValue Then
            lngLB = Q
            C = lngLB
        Else
            If bolFindFirst Then
                Do While (lngArr(Q) = lngArr(Q - 1)) And (Q > lngLB)
                    Q = Q - 1
                Loop
            End If
            IsInArray = Q
            Exit Function
        End If
    Loop
Exit Function

NotFound:
    IsInArray = -1
End Function

'// by BlackZer0x
Public Function ExitsInArrayNR(ByRef vValue As Long, ByRef vBuff() As Long, ByRef p As Long) As Boolean
Dim lng_lb                      As Long
Dim lng_Ub                      As Long
    lng_lb = LBound(vBuff&())
    lng_Ub = UBound(vBuff&())
    If Not vBuff&(lng_Ub) > vBuff&(lng_lb) Then
        Dim t                           As Long
        t = lng_Ub
        lng_Ub = lng_lb
        lng_lb = t
    End If
    Do Until ExitsInArrayNR
        Select Case vValue
            Case vBuff&(lng_lb&)
                p& = lng_lb&
                ExitsInArrayNR = True
            Case vBuff&(lng_Ub&)
                p& = lng_Ub&
                ExitsInArrayNR = True
            Case Else
                p = (lng_lb& + lng_Ub&) / 2
                If p <> lng_lb& And p& <> lng_Ub& Then
                    If vBuff&(p&) < vValue& Then
                        lng_lb = p
                    ElseIf vBuff&(p&) > vValue& Then
                        lng_Ub = p
                    ElseIf vBuff&(p&) = vValue& Then
                        ExitsInArrayNR = True
                    End If
                Else
                    Exit Do
                End If
        End Select
    Loop
End Function

Resultado:


DoEvents! :P
222  Programación / Programación Visual Basic / Re: Convertir numeros a letras en: 9 Mayo 2011, 10:17 am
.
Numeros a letras:  < Click Aquí >

Dulces Lunas!¡.
Creo que pusiste mal el link... :silbar: :laugh:

[OffTopic]
@Black debes revisar tu blog, de repente se volvió loco y me empezó a cargar todo el rato la misma entrada del blog. :-\
[/OffTopic]

DoEvents! :P
223  Programación / Programación General / Re: Duda simple expresiones regulares en: 7 Mayo 2011, 17:46 pm
Gracias Novlucker, resulto :-*
224  Programación / Programación General / Duda simple expresiones regulares en: 7 Mayo 2011, 17:02 pm
Hola buenas, vengo aquí con un problemilla muy sencillo que tengo con RegExp.
Necesito validar nombres de usuario que sólo pueden contener : números, letras y "_" ; tener un mínimo de un carácter y un máximo de 15.
Para ello, pensé esto:
Código:
[\w_]{1,15}
El problema es que si tengo esto:
Código:
=Usu@rio^
La validación me da positiva, pues, encuentra caracteres alfanuméricos... :-(
Sólo quiero que me admita (\w y "_") nada más. ;)
¿Me echáis una mano?
Gracias :-*

DoEvents! :P
225  Programación / Programación Visual Basic / Re: [Solucionado] Separar una Cadena de Texto Caracter Por Caracter en: 5 Mayo 2011, 14:29 pm
Oops! :-\ gracias, se me escapó... :-[
corregido
...
P.D.: hay ya que tocar de nuevo la wiki no crees xP.

Temibles Lunas!¡.
Si hermano, estuve bastante ocupado estos últimos meses por estudios, pero a partir de Junio podré meterme con ello de nuevo ;)

DoEvents! :P
226  Programación / Programación Visual Basic / Re: [Solucionado] Separar una Cadena de Texto Caracter Por Caracter en: 4 Mayo 2011, 13:18 pm
...
Por cierto que es StronV?

GRACIAS POR LEER!!!
Me da que raulito se refiere es a la función StrConv()... :xD :silbar:

Dejo un ejemplo (aunque repito que mi manera favorita es la de BlackZer0x :rolleyes: :-*) :
Código
  1. Option Explicit
  2.  
  3. Private Static Function String2Array(ByRef strText$, ByRef strOutPut$()) As Boolean
  4. Dim bytStr() As Byte
  5. Dim Q&, lngLen&
  6.  
  7.    lngLen = (LenB(strText) \ 2) - 1
  8.  
  9.    If lngLen And &H80000000 Then Exit Function
  10.  
  11.    '// Aquí el famoso "StronV"... xP
  12.    bytStr = Strings.StrConv(strText, vbFromUnicode)
  13.    ReDim strOutPut$(0 To lngLen)
  14.  
  15.    For Q = 0 To lngLen
  16.        strOutPut(Q) = Strings.ChrW$(bytStr(Q))
  17.    Next Q
  18.  
  19.    String2Array = True
  20. End Function
  21.  
  22. Private Sub Form_Load()
  23. Dim varItem
  24. Dim strO$()
  25.  
  26.    If String2Array("Psyke1", strO) Then
  27.        For Each varItem In strO
  28.            Debug.Print varItem
  29.        Next varItem
  30.    End If
  31. End Sub

Retorna:
Código:
P
s
y
k
e
1

DoEvents! :P
227  Programación / Programación Visual Basic / Re: ayuda con un keylogger vb6 en: 4 Mayo 2011, 00:31 am
Auch! Lo siento, pero me duele la vista con estos códigos.
Hacer caso a seba123neo y hacerlo con hooks, eso es una chapuzada...

DoEvents! :P
228  Programación / Programación Visual Basic / Re: [Solucionado] Separar una Cadena de Texto Caracter Por Caracter en: 3 Mayo 2011, 22:36 pm
No se si sea lo mas rapido. Pero lo mas simple y rapido (midiendo instrucciones) es usar stronv y poniendolo a un array de bytes y de ahi se recorre facilmente
Más lento que la forma de BlackZer0x, pero más simple.

La tuya usa nagia negra, la mia magia blanca :xD
Jajajajajaja :laugh:
¡Exacto! ;)

DoEvents! :P
229  Programación / Programación Visual Basic / Re: Arreglo como parametro Generico(Solucionado) en: 30 Abril 2011, 10:44 am
.
No les recomiedno usar Not para ver si esta inicializada la variable , en codigos largos y complejos causa errores muy desagradables es por eso que le di el codigo de CopyMemory.

Dulces Lunas!¡.
¿Compilado también? :huh:

DoEvents! :P
230  Programación / Programación Visual Basic / Re: Arreglo como parametro Generico(Ayuda) en: 29 Abril 2011, 21:25 pm
También con el truco del NotNot podemos comprobar si está iniciado el array:
Código
  1. If Not Not iArray Then
  2.    '// Haz algo...
  3. End If

Es la forma más rápida, en el IDE puede dar problemas pero compilado funciona 100%.
Para prevenir el bug en el IDE haz:
Código
  1. Private Form_Load()
  2. Dim IDEbug&()
  3.    '// Prevenir el NotNot bug.
  4.    Debug.Assert Not IDEbug Or App.hInstance
  5. End Sub

Código:
Advertencia - mientras estabas escribiendo, una nueva respuesta fue publicada. Probablemente desees revisar tu mensaje.
:-\

DoEvents! :P
Páginas: 1 ... 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [23] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 ... 128
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines