Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Sanlegas en 15 Septiembre 2011, 04:16 am



Título: [Reto] IsHour
Publicado por: Sanlegas en 15 Septiembre 2011, 04:16 am
Bueno para seguir practicando y calentando, ahora por que no un reto para saber si una expresión es una hora  :laugh:, creo que es mas facil pero bueno  :P
la fecha limite es el 18/09/2011 y como no hay una funcion de vb que haga lo mismo (corregirme si me equivoco) se hara en lo mas logico, que acepte el siguiente formato  HH:MM:SS  (horas,minutos,segundos) y las siguientes reglas

* Debe aceptar de "00:00:00" hasta "23:59:59"
* En base a lo anterior y para hacerlo mas interesante lo correcto es llenar los dos lugares, si es menor que 10 se pondra un cero, ejemplo:
"05:59:59" ----> Correcto
"5:59:59" ---- > Falso
* Debe devolver True si la hora es correcta
* El delimitador para separar los numeros es ":"


Buena suerte a todos.. un saludo !  :D


Título: Re: [Reto] IsHour
Publicado por: x64core en 15 Septiembre 2011, 05:23 am
creo tener la mia :xD

Código
  1. Function R100(XXX As String) As Boolean
  2. Dim X() As String
  3.  
  4. X = Split(XXX, ":")
  5. If (CInt(X(0)) < 24) And (CInt(X(1) < 60)) And (CInt(X(2) < 60)) Then R100 = True
  6. End Function
  7.  


Título: Re: [Reto] IsHour
Publicado por: Sanlegas en 15 Septiembre 2011, 05:30 am
@Raul100:

R100("aa:aa:aa") --- > Fail

para hacerlo mas interesante acabo de agregar una nueva regla  :P


Título: Re: [Reto] IsHour
Publicado por: BlackZeroX en 15 Septiembre 2011, 07:03 am
Es cuestion solo de modificar algunas cosillas de la funcion isDate. Por ejemplo aqui tienen la mia Donde solo Modifique la 2da funcion isDate de mi tutela. solo Modifique los rangos... y cambio el select case por un simple if then para verificar rangos...

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Long)
  5.  
  6. '   //  Formato aceptado   HH:MM:SS, H:/MM:S, HH:MM:S, etc!&#161;.
  7. Public Function isHour_BlackZX(ByRef sStr As String, Optional bExtrictic As Boolean = True) As Boolean
  8. Dim lChar           As Long
  9. Dim lVal            As Long
  10. Dim lConvert(2)     As Long
  11.  
  12. Dim lDim            As Long
  13. Dim lMult           As Long
  14. Dim pStr            As Long
  15. Dim pChar           As Long
  16.  
  17.    pStr = LenB(sStr)
  18.    If (bExtrictic) Then
  19.        If Not (pStr = &H10) Then Exit Function
  20.    ElseIf (pStr < &H5) And (pStr <= &H8) Then
  21.        Exit Function
  22.    End If
  23.  
  24.    pStr = StrPtr(sStr) + (pStr - &H2)
  25.    pChar = VarPtr(lChar)
  26.  
  27.    lDim = &H2
  28.    lMult = &H1
  29.    lConvert(lDim) = &H0
  30.  
  31.    Do Until StrPtr(sStr) > pStr
  32.        RtlMoveMemory pChar, pStr, &H2  '   //  Dos bytes = char...
  33.        lVal = (lChar And &HFF)
  34.        If (lVal = &H3A) Then
  35.            lDim = (lDim - &H1)
  36.            If ((lDim And &H80000000) = &H80000000) Then Exit Function
  37.            lMult = &H1
  38.        Else
  39.            If ((lVal > &H39) Or (lVal < &H30)) Then Exit Function
  40.            lConvert(lDim) = lConvert(lDim) + ((lVal - &H30) * lMult)
  41.            lMult = (lMult * &HA)
  42.        End If
  43.        pStr = (pStr - &H2)
  44.    Loop
  45.  
  46.    If (lConvert(&H0) > &H17) Or (lConvert(&H1) > &H3B) Or (lConvert(&H2) > &H3B) Then Exit Function
  47.  
  48.    isHour_BlackZX = True
  49.  
  50. End Function
  51.  
  52. Private Sub Form_Load()
  53.    MsgBox isHour_BlackZX("23:59:9") & vbCrLf & _
  54.           isHour_BlackZX("23:59:9", False)
  55. End Sub
  56.  
  57.  

2da version, leyendo 32bits (la anterior es a 16bits pero es mas legible), esta un tanto ofuscada...

Código:

Option Explicit
 
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Long)

Public Function addAscToNumber(ByVal lAsc As Long, ByRef rArrConvert() As Long, ByRef lIndex As Long, ByRef lMult As Long) As Long
    addAscToNumber = (-1)
    If (lAsc = &H3A) Then
        lMult = &H1
        lIndex = (lIndex + &H1)
    Else
        If (lAsc = &H0) Then addAscToNumber = &H1: Exit Function
        If ((lAsc > &H39) Or (lAsc < &H30)) Then addAscToNumber = &H0: Exit Function
        rArrConvert(lIndex) = (rArrConvert(lIndex) * lMult) + (lAsc - &H30)
        lMult = (lMult * &HA)
    End If
End Function

'   //  Formato aceptado   HH:MM:SS, H:/MM:S, HH:MM:S, etc!¡.
Public Function isHour_BlackZX(ByRef sStr As String, Optional bExtrictic As Boolean = True) As Boolean
Dim lChar           As Long
Dim lConvert(2)     As Long
Dim lIndex          As Long
Dim lMult           As Long
Dim lStrLnB         As Long
Dim pStr            As Long
Dim pStrLim         As Long
Dim pChar           As Long
    lStrLnB = LenB(sStr)
    If (bExtrictic) Then
        If Not (lStrLnB = &H10) Then Exit Function
    ElseIf (lStrLnB < &H5) And (lStrLnB <= &H8) Then
        Exit Function
    End If
    pStr = StrPtr(sStr)
    pStrLim = (lStrLnB + pStr - &H2)
    pChar = VarPtr(lChar)
    lMult = &H1
    For pStr = pStr To pStrLim Step &H4
        RtlMoveMemory pChar, pStr, &H4  '   //  Cuatro bytes = 4 --> 2 Char...
        Select Case addAscToNumber((lChar And &HFF), lConvert, lIndex, lMult)
            Case (1): Exit For
            Case (0): Exit Function
        End Select
        If (lIndex > &H2) Then Exit Function
        Select Case addAscToNumber(((lChar And &HFF0000) / &H10000), lConvert, lIndex, lMult)
            Case (1): Exit For
            Case (0): Exit Function
        End Select
        If (lIndex > &H2) Then Exit Function
    Next
    If (lConvert(&H0) > &H17) Or (lConvert(&H1) > &H3B) Or (lConvert(&H2) > &H3B) Then Exit Function
    isHour_BlackZX = True
End Function

Private Sub Form_Load()
    MsgBox isHour_BlackZX("23:59:9") & vbCrLf & _
           isHour_BlackZX("23:59:9", False)
End Sub


Output:

Código:

Falso
Verdadero


Dulces Lunas!¡.


Título: Re: [Reto] IsHour
Publicado por: Sanlegas en 15 Septiembre 2011, 07:27 am
@BlackZeroX▓▓▒▒░░: si tienes razon, pero es por que tu función es mas generica... , y claro para resolver un problema puedes usar diferentes soluciones...
Por cierto:
isHour_BlackZX("14:59:09") --- > Fail

Salu2 !


Título: Re: [Reto] IsHour
Publicado por: BlackZeroX en 15 Septiembre 2011, 08:08 am

isHour_BlackZX("14:59:09") --- > Fail


jaja sorry se me ofusco el LenB()...

Código
  1.  
  2. Dim lMult           As Long
  3. Dim pStr            As Long
  4. Dim pChar           As Long
  5.  
  6.    pStr = LenB(sStr)
  7.    If (bExtrictic) Then
  8.        If Not (pStr = &H8) Then Exit Function
  9.    ElseIf (pStr < &H5) And (pStr <= &H8) Then
  10.        Exit Function
  11.    End If
  12.  
  13.  

El valor &H8 deberia ser &H10 ya lo corregi, gracias por el aviso.

Edito:

Valen espacios en blanco? digo para meterle algo para que no diga False en casos como "23:59:59 " y " 23:59:59" o ambos casos " 23:59:59 ".

Dulces Lunas!¡.


Título: Re: [Reto] IsHour
Publicado por: Psyke1 en 15 Septiembre 2011, 11:05 am
Ui que interesante, se me ocurren muchas formas de hacerlo, podré todas las que se me ocurran, con RegExp sería sencillísimo:
Código:
^([01]\d|2[0-3])\:[0-5]\d\:[0-5]\d$
(Después lo desarollo antes de que se me adelante raul338) :silbar: :xD

Mi primera forma de hacerlo (dudo que sea la más rápida, pero igual si la más corta):
Código
  1. Option Explicit
  2.  
  3. Public Static Function IsHour_Psyke1(ByRef sHour$) As Boolean
  4. On Error Resume Next
  5.    IsHour_Psyke1 = TimeValue(sHour) And (LenB(sHour) = 16)
  6. End Function

Test:
Código
  1. Private Sub Form_Load()
  2.    Debug.Print IsHour_Psyke1("12:13:12")
  3.    Debug.Print IsHour_Psyke1("24:13:12")
  4. End Sub

Resultado:
Código:
True
False

DoEvents! :P


Título: Re: [Reto] IsHour
Publicado por: Psyke1 en 15 Septiembre 2011, 12:49 pm
Mi segunda forma de hacerlo (sé que se puede simplificar código con bucles, pero yo lo elijo hacer así  :rolleyes:)


Código
  1. '//En un módulo de clase.
  2.  
  3. Option Explicit
  4. Private Declare Sub PutMem4 Lib "msvbvm60.dll" (ByVal Ptr&, ByVal Value&)
  5. Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
  6.  
  7. Private lngAscHeader&(5), intAsc%()
  8.  
  9. Public Static Function IsHour_Psyke12(ByRef sHour$) As Boolean
  10.    If LenB(sHour) = 16 Then
  11.        lngAscHeader(3) = StrPtr(sHour)
  12.  
  13.        '//Check ":"
  14.        If intAsc(2) = 58 And intAsc(5) = 58 Then
  15.            '//Hours
  16.            If intAsc(0) < 48 Or intAsc(0) > 50 Then Exit Function
  17.  
  18.            If intAsc(1) < 48 Then Exit Function
  19.            If intAsc(0) = 50 Then
  20.                If intAsc(1) > 51 Then Exit Function
  21.            Else
  22.                If intAsc(1) > 57 Then Exit Function
  23.            End If
  24.  
  25.            '//Minutes
  26.            If intAsc(3) < 48 Or intAsc(3) > 53 Then Exit Function
  27.            If intAsc(4) < 48 Or intAsc(4) > 57 Then Exit Function
  28.  
  29.            '//Seconds
  30.            If intAsc(6) < 48 Or intAsc(6) > 53 Then Exit Function
  31.            If intAsc(7) < 48 Or intAsc(7) > 57 Then Exit Function
  32.  
  33.            IsHour_Psyke12 = True
  34.        End If
  35.    End If
  36. End Function
  37.  
  38. Private Sub Class_Initialize()
  39.    lngAscHeader(0) = 1
  40.    lngAscHeader(1) = 2
  41.    lngAscHeader(4) = &H7FFFFFFF
  42.    PutMem4 VarPtrArray(intAsc), VarPtr(lngAscHeader(0))
  43. End Sub
  44.  
  45. Private Sub Class_Terminate()
  46.    PutMem4 VarPtrArray(intAsc), 0
  47. End Sub

Test:
Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. Dim c As New Class1
  5.  
  6.    Debug.Print String$(50, "=")
  7.    Debug.Print c.IsHour_Psyke12(Time$)      'True
  8.    Debug.Print c.IsHour_Psyke12("23:59:59") 'True
  9.    Debug.Print c.IsHour_Psyke12("00:00:00") 'True
  10.    Debug.Print c.IsHour_Psyke12("34:54:13") 'False
  11.    Debug.Print c.IsHour_Psyke12("14:64:24") 'False
  12.    Debug.Print c.IsHour_Psyke12("22:07:70") 'False
  13.  
  14. Set c = Nothing
  15. End Sub

Resultados:
Código:
==================================================
True
True
True
False
False
False


EDIT:

Mi tercera forma de hacerlo (no creo que sea muy rápida, tan solo doy más opciones...  ;) ):
Código
  1. '//En un módulo de clase.
  2.  
  3. Option Explicit
  4. Private oRegExp As Object
  5.  
  6. Public Static Function IsHour_Psyke13(ByRef sHour$) As Boolean
  7.    IsHour_Psyke13 = oRegExp.Test(sHour)
  8. End Function
  9.  
  10. Private Sub Class_Initialize()
  11.    Set oRegExp = CreateObject("VBScript.RegExp")
  12.    With oRegExp
  13.        .Pattern = "^([01]\d|2[0-3])\:[0-5]\d\:[0-5]\d$"
  14.        .Global = True
  15.    End With
  16. End Sub
  17.  
  18. Private Sub Class_Terminate()
  19.    Set oRegExp = Nothing
  20. End Sub

Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. Dim c As New Class1
  5.  
  6.    Debug.Print String$(50, "=")
  7.    Debug.Print c.IsHour_Psyke13(Time$)      'True
  8.    Debug.Print c.IsHour_Psyke13("23:59:59") 'True
  9.    Debug.Print c.IsHour_Psyke13("00:00:00") 'True
  10.    Debug.Print c.IsHour_Psyke13("34:54:13") 'False
  11.    Debug.Print c.IsHour_Psyke13("14:64:24") 'False
  12.    Debug.Print c.IsHour_Psyke13("22:07:70") 'False
  13.  
  14. Set c = Nothing
  15. End Sub

Resultados:
Código:
==================================================
True
True
True
False
False
False


EDIT2:

Mi cuarta forma de hacerlo:
Código
  1. Option Explicit
  2.  
  3. Public Static Function IsHour_Psyke14(ByRef sHour$) As Boolean
  4. Dim h As Byte, m As Byte, s As Byte
  5. On Error GoTo NoHour:
  6.    If LenB(sHour) = 16 Then
  7.        If InStrB(1, ":", MidB$(sHour, 5, 2), vbBinaryCompare) = 0 Then Exit Function
  8.        If InStrB(1, ":", MidB$(sHour, 11, 2), vbBinaryCompare) = 0 Then Exit Function
  9.  
  10.        h = LeftB$(sHour, 4) + 0
  11.        If h > 23 Then Exit Function
  12.        m = MidB$(sHour, 7, 4) + 0
  13.        If m > 59 Then Exit Function
  14.        s = RightB$(sHour, 4) + 0
  15.        If s > 59 Then Exit Function
  16.  
  17.        IsHour_Psyke14 = True
  18.    End If
  19.    Exit Function
  20. NoHour:
  21. End Function

Test:
Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.    Debug.Print String$(50, "=")
  5.    Debug.Print IsHour_Psyke14(Time$)      'True
  6.    Debug.Print IsHour_Psyke14("23:59:59") 'True
  7.    Debug.Print IsHour_Psyke14("00:00:00") 'True
  8.    Debug.Print IsHour_Psyke14("34:54:13") 'False
  9.    Debug.Print IsHour_Psyke14("14:64:24") 'False
  10.    Debug.Print IsHour_Psyke14("22:04:70") 'False
  11. End Sub

Resultados:
Código:
==================================================
True
True
True
False
False
False

PD: Lo próximo que tenga que decir haré un comentario nuevo que sino hago una pág kilométrica. :-X :laugh:

DoEvents! :P


Título: Re: [Reto] IsHour
Publicado por: raul338 en 15 Septiembre 2011, 15:02 pm
Buena idea con el reto :D yo me olvide que iba a proponer de reto y después se me paso :xD

Hice lo mismo que BlackZeroX, agarre mi IsDate y lo transforme a IsHour!! :xD
Ademas de que lo optimize (y puedo optimizar tambien el IsDate, pero ya fue xD)
Código
  1. Public Function IsHour_r338(str As String) As Boolean
  2. If str = vbNullString Then Exit Function
  3. If LenB(str) <> 16 Then Exit Function
  4.  
  5.    Dim j As Long, k As Long, vTemp As Byte, jp As Long
  6.    Dim strp As Long
  7.    strp = StrPtr(str)
  8.    jp = VarPtr(j)
  9.    For k = 0 To 14 Step 2
  10.        Call RtlMoveMemory(jp, strp + k, 1)
  11.        Select Case k
  12.            Case 0
  13.                If j < 48 And j > 50 Then Exit Function
  14.                vTemp = (j - 48) * 10
  15.            Case 2
  16.                If j < 48 And j > 57 Then Exit Function
  17.                vTemp = vTemp + (j - 48)
  18.                If vTemp > 23 Then Exit Function
  19.            Case 4, 10: If j <> 58 Then Exit Function
  20.            Case 6, 12
  21.                If j < 48 And j > 53 Then Exit Function
  22.                vTemp = (j - 48) * 10
  23.            Case 8, 14
  24.                If j < 48 And j > 57 Then Exit Function
  25.                vTemp = vTemp + (j - 48)
  26.                If vTemp > 59 Then Exit Function
  27.        End Select
  28.    Next
  29.    IsHour_r338 = True
  30. End Function
  31.  


Título: Re: [Reto] IsHour
Publicado por: BlackZeroX en 15 Septiembre 2011, 19:53 pm
.
No me agradan los BadTypeConvert/EvilTypeConvert que hace Psyke1 aun que en fin de cuentas funciona pero no me agradan...  :¬¬

Dulces Lunas!¡.


Título: Re: [Reto] IsHour
Publicado por: Psyke1 en 15 Septiembre 2011, 22:37 pm
¿Ahora mejor? :xD :-*

DoEvents! :P


Título: Re: [Reto] IsHour
Publicado por: raul338 en 15 Septiembre 2011, 23:40 pm
Usando el mismo estilo de prueba que use en IsDate :rolleyes:

Código:
 === Reto IsHour ====
09-15-2011 18:41:27

Testeo de calidad
==============================
00:00:00 Psyke1 FAILS

Testeo de falsos
==============================
5:59:59 Psyke1 FAILS


Testeo de velocidades
==============================
300000 vueltas

413,168 msec BlackZeroX
1.198,057 msec Psyke1
572,217 msec Psyke14
215,601 msec raul338


Título: Re: [Reto] IsHour
Publicado por: BlackZeroX en 15 Septiembre 2011, 23:47 pm
¿Ahora mejor? :xD :-*

Sigue igual... ya que para sumar un numero a un valor guardado en una string se recurre al BadTypeConvert/EvilTypeConvert, lo digo solo por que a simple vista un "Novato/Intermedio" puede confundirse un poco y por eso no me gusta, no se digiere rapido, aun asi genial funcion!¡.

P.D.:
    Sigues en CrazedCountryRebels?, estuve en españa hace 1 mes (vacaciones) y busque ese restaurante o lo que sea no lo haye jajaja... si era españa vdd?

Dulces Lunas!¡.


Título: Re: [Reto] IsHour
Publicado por: Psyke1 en 16 Septiembre 2011, 00:43 am
@BlackZero
Ahh, ok, te lo había copiado de un código tuyo de no sé donde... :silbar:
Viniste a España y no me avisas. :-( :xD
Sí, sigo en el grupo, sé que no es muy metal para ti, pero bueno... :laugh: ;)

@raul
Gracias, corregida... :)
Que listo, justo pruebas con mis funciones lentas... :rolleyes:
Si probamos con mi función más rápida IsHour_Psyke12 las cosas cambian. :silbar:

Código:
Option Explicit
 
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDst As Long, ByVal pSrc As Long, ByVal ByteLen As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
Dim t As New CTiming, c As New Class1, i&, r&, a$(), b As Boolean

    Me.AutoRedraw = True
    a() = Split("34:23:45 5:59:59 10:45:67 raulfeo 00:00:00 14:57:79 111:23:4", " ")
    
    t.Reset
    For i = 0 To 200000
        For r = 0 To 6
            b = IsHour_r338(a(r))
        Next
    Next
    Me.Print t.sElapsed, "raul338"
    Sleep 1000
    
    t.Reset
    For i = 0 To 200000
        For r = 0 To 6
            b = isHour_BlackZX(a(r))
        Next
    Next
    Me.Print t.sElapsed, "Black"
    Sleep 1000
    
    t.Reset
    For i = 0 To 200000
        For r = 0 To 6
            b = c.IsHour_Psyke12(a(r))
        Next
    Next
    Me.Print t.sElapsed, , "Psyke13"

    Set c = Nothing
    Set t = Nothing
End Sub

Resultado:
(http://img27.imageshack.us/img27/5811/carreteraeneldesierto10.jpg)

DoEvents! :P



Título: Re: [Reto] IsHour
Publicado por: BlackZeroX en 16 Septiembre 2011, 01:28 am
@ A mi criterio ni la de Raul338 ni la mia son legiles (me tarde un poco en entender la de Raul338, mas que nada como comprobaba los rangos, ya que esta dispersa esa region)... y la mia esta un poco ofuscada... mas aun sin comentarios, almenos que seas yo  :xD.

Para mi la funcion mas rapida y legible es la de IsHour_Psyke12, no tengo que comprobarla para saber eso.

Dulces Lunas!¡.


Título: Re: [Reto] IsHour
Publicado por: Elemental Code en 16 Septiembre 2011, 03:30 am
Rustic Mode ON!

[Rustic]

Código
  1. Public Function eCode(ByRef Time As String) As Boolean
  2.    On Error GoTo Fallo
  3.    If Len(Time) <> 8 Then Exit Function
  4.    Dim sTime() As String
  5.    sTime = Split(Time, ":")
  6.    If CLng(sTime(0)) >= 0 And CLng(sTime(0)) <= 23 And _
  7.       CLng(sTime(1)) >= 0 And CLng(sTime(1)) <= 59 And _
  8.       CLng(sTime(2)) >= 0 And CLng(sTime(2)) <= 59 Then eCode = True
  9. Fallo:
  10. End Function

[/Rustic]


Título: Re: [Reto] IsHour
Publicado por: Sanlegas en 18 Septiembre 2011, 00:02 am
Bueno aqui el mio...  ;D

Código
  1. Public Function IsHour(ByRef Expresion As String) As Boolean
  2. Dim C()         As Byte
  3. Dim L           As Integer
  4. Dim P           As Integer
  5. Dim F           As Boolean
  6.  
  7. L = Len(Expresion)
  8. If (L And &H8) Then
  9.    L = (L - &H8)
  10.    If (L Or &H0) = &H0 Then
  11.        C = StrConv(Expresion, vbFromUnicode)
  12.        P = &H2
  13. Sig0:
  14.        L = C(P)
  15.        If (L And &H20) Then
  16.            L = (L - &H20)
  17.            If (L And &H10) Then
  18.                L = (L - &H10)
  19.                If (L And &H8) Then
  20.                    L = (L - &H8)
  21.                    If (L And &H2) Then
  22.                        L = (L - &H2)
  23.                        If (L Or &H0) = &H0 Then
  24.                            If (P And &H4) Then
  25.                                GoTo Sig
  26.                            Else
  27.                                P = &H5
  28.                                GoTo Sig0
  29.                            End If
  30.                        End If
  31.                    End If
  32.                End If
  33.            End If
  34.        End If
  35.        Exit Function
  36. Sig:
  37.        L = C(0)
  38.        L = (L - &H33)
  39.        If (L And &H40) Then
  40.            L = (C(0) - &H30)
  41.            If (L And &H40) Then
  42.                Exit Function
  43.            Else
  44.                If (L And &H2) Then F = True
  45.                GoTo Sig2
  46.            End If
  47.        End If
  48.        Exit Function
  49. Sig2:
  50.        L = C(1)
  51.        L = (L - &H3A)
  52.        If (L And &H40) Then
  53.            L = (-&HB - L)
  54.            If (L And &H10) Then
  55.                L = ((Not L) - &H4)
  56.                If (L And &H4) Then
  57.                    GoTo Sig3
  58.                Else
  59.                    If Not F Then GoTo Sig3
  60.                End If
  61.            End If
  62.        End If
  63.        Exit Function
  64. Sig3:
  65.        P = &H3
  66. Sig4:
  67.        L = C(P)
  68.        L = (L - &H36)
  69.        If (L And &H40) Then
  70.            L = (-L - &H7)
  71.            If (L And &H8) Then
  72.                P = (P + &H3)
  73.                If (P And &H8) Then
  74.                    P = &H4
  75.                    GoTo Sig5
  76.                Else
  77.                    GoTo Sig4
  78.                End If
  79.            End If
  80.        End If
  81.        Exit Function
  82. Sig5:
  83.        L = C(P)
  84.        L = (L - &H3A)
  85.        If (L And &H40) Then
  86.            L = (-L - &HB)
  87.            If (L And &H10) Then
  88.                P = (P + &H3)
  89.                If (P And &H8) Then IsHour = True Else GoTo Sig5
  90.            End If
  91.        End If
  92.    End If
  93. End If
  94. End Function
  95.  

Alguien puede subir el proyecto completo del reto?, salu2 !


Título: Re: [Reto] IsHour
Publicado por: BlackZeroX en 18 Septiembre 2011, 02:57 am
@BlackZero
Ahh, ok, te lo había copiado de un código tuyo de no sé donde... :silbar:

lo se pero yo lo hacia de la manera (Solo en/para numeros).

TipoNumerico1 = (TipoNumerico1.2 + TipoNumerico2)

Donde: TipoNumerico1.2 es del mismo tipo que TipoNumerico1 pero con valor 0... y el tipo resultante sera del tipo TipoNumerico1.2, mas no del TipoNumerico2...

ej.:

Código
  1.  
  2. dim lVal as long
  3. dim bVal as byte
  4.  
  5. lval = (&H0 + bVal)
  6.  
  7.  

y tu lo haces de una manera un poco mas ofuscada... ya que como sabras si pones

Código
  1.  
  2. dim lVal as long
  3. Const VAL as string = "10"
  4.  
  5. VAL
  6. lval = (&H0 + VAL) ' // mas no (VAL + &H0)
  7.  
  8.  

Realizara su trabajo, pero le das mas trabajo independiente a el lenguaje y sabra solo el que resultados salgan... ya que como sabras "10" se deberia transformar a un valor de tipo numerico (Lo que yo hago en mi codigo y que seguro Raul338 me copio..  :xD :xD na no te creas es un gran programador  ;) :))