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

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Ayuda Con Lotto Code
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda Con Lotto Code  (Leído 2,222 veces)
iory330

Desconectado Desconectado

Mensajes: 42


Ver Perfil
Ayuda Con Lotto Code
« en: 3 Octubre 2009, 08:41 am »

Hola Comunidad:
Bueno he estado aprendiendo Vb por mi cuenta asi que vi que una de las formas es estudiando los codigos y ver el trabajo de otros. asi que me descargue el source en VB 6 del International Lotto Uk, pero No entiendo la ultima parte me gustaria saber si alguien podria hecharme una mano.


Source

Código
  1. Option Explicit
  2.  
  3. Dim iBallsToMake As Integer
  4.  
  5. Private Sub Form_Load()
  6.    ' Initialize random procedure:
  7.    Randomize
  8. End Sub
  9.  
  10. Private Function Get_RANDOM(lowerbound As Integer, upperbound As Integer) As Integer
  11.    ' The RND formula!
  12.    ' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
  13.    Get_RANDOM = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
  14. End Function
  15.  
  16. Private Sub lblURL_Click(Index As Integer)
  17.    Dim sURL As String
  18.    sURL = Trim(lblURL(Index).Caption)
  19.    Shell "explorer " & sURL, vbMaximizedFocus
  20. End Sub
  21.  
  22. Private Sub cmdMake_Click()
  23.  
  24.    ' Disable button and properties:
  25.    cmdMake.Enabled = False
  26.    txtBallCount.Enabled = False
  27.    txtMinBall.Enabled = False
  28.    txtMaxBall.Enabled = False
  29.  
  30.    Dim i As Integer
  31.  
  32.    ' Hide all balls and set labels to "77":
  33.    For i = imgBall.LBound To imgBall.UBound
  34.        imgBall(i).Visible = False
  35.        lblNum(i).Visible = False
  36.        lblNum(i).Caption = "77"
  37.    Next i
  38.  
  39.    ' Get the number of balls to make:
  40.    iBallsToMake = Val(txtBallCount.Text)
  41.  
  42.    ' Check if number is between 1 and 7:
  43.    If iBallsToMake > 7 Then
  44.        iBallsToMake = 7
  45.        txtBallCount.Text = "7"
  46.    ElseIf iBallsToMake <= 0 Then
  47.        iBallsToMake = 1
  48.        txtBallCount.Text = "1"
  49.    End If
  50.  
  51.    ' Start the process:
  52.    Timer1.Enabled = True
  53.  
  54. End Sub
  55.  
  56. Private Sub Timer1_Timer()
  57.  
  58.    ' Are there balls to make?
  59.    If iBallsToMake <= 0 Then
  60.        ' Stop timer:
  61.        Timer1.Enabled = False
  62.        ' Enable properties:
  63.        cmdMake.Enabled = True
  64.        txtBallCount.Enabled = True
  65.        txtMinBall.Enabled = True
  66.        txtMaxBall.Enabled = True
  67.        Exit Sub ' Done!
  68.    End If
  69.  
  70.  
  71.    ' Make ball visible:
  72.    imgBall(7 - iBallsToMake).Visible = True
  73.    lblNum(7 - iBallsToMake).Visible = True
  74.  
  75.    Dim iNewNum As Integer
  76.    Dim i As Integer
  77.    Dim iTryAgainCounter As Integer
  78.  
  79.    iTryAgainCounter = 0
  80.  
  81. try_again:
  82.  
  83.    ' Avoid hand up with max ball 2 and 7 balls :)
  84.    If iTryAgainCounter > 100 Then
  85.         ' Set the ball value:
  86.         lblNum(7 - iBallsToMake).Caption = "?"
  87.         GoTo one_less
  88.    End If
  89.  
  90.    ' Get the random value:
  91.    iNewNum = Get_RANDOM(Val(txtMinBall.Text), Val(txtMaxBall.Text))
  92.  
  93.    ' Avoid falling the same number again:
  94.    For i = imgBall.LBound To imgBall.UBound
  95.        If Val(lblNum(i).Caption) = iNewNum Then
  96.            iTryAgainCounter = iTryAgainCounter + 1
  97.            GoTo try_again
  98.        End If
  99.    Next i
  100.  
  101.    ' Set the ball value:
  102.    lblNum(7 - iBallsToMake).Caption = iNewNum
  103.  
  104. one_less:
  105.    ' Ok, one ball is there!
  106.    iBallsToMake = iBallsToMake - 1
  107.  
  108. End Sub
  109.  
  110.  

-----------------------------------------------------------------------------------------------

Duda:

Bueno el problema es el siguiente, supuestamente en el codigo con variable iballstomake es ekivalente al numero de bolas que se va a caer al azar, entonces

 
Código
  1.  
  2.    ' Make ball visible:
  3.    imgBall(7 - iBallsToMake).Visible = True
  4.    lblNum(7 - iBallsToMake).Visible = True
  5.  
Esto solo haria aparecer a la primera bola y no las 7 que supuestamente deberia estar alli.

Es mas otra cosa que no entiendo, porque pone esta condicion si itryagaincounter es dificil que sea mayor a 100 x lo que nunka se cumpliria.....

Código
  1.    If iTryAgainCounter > 100 Then
  2.         ' Set the ball value:
  3.         lblNum(7 - iBallsToMake).Caption = "?"
  4.         GoTo one_less
  5.    End If
  6.  
  7.  
  8.  
La verdad estoy con muchas ganas d aprender sin embargo creo... que necesitare de ayuda...
Espero que haya sido claro con mi explicacion.


Salu2




« Última modificación: 3 Octubre 2009, 17:52 pm por iory330 » En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Ayuda Con Lotto Code
« Respuesta #1 en: 3 Octubre 2009, 09:13 am »

Código
  1.    ' Make ball visible:
  2.    imgBall(7 - iBallsToMake).Visible = True
  3.    lblNum(7 - iBallsToMake).Visible = True
  4.  

La variable iBallsToMake es absesible en todos los procesos y como esta en un timer, este al cumplir las 7 rondas mostrara de 1 en una es decir asi

Código:
6
65
654
6543
65432
6543210

PORQUE? por que al activar el proces cmdMake_Click se establece  iBallsToMake = Val(txtBallCount.Text)  y despues activa el timer, despues en este hace lo que ya te mencione y cuando revisa que iBallsToMake  <= 0 se desactiva el timer y termina su siclo.


ahora para esto otro:

Código
  1.    If iTryAgainCounter > 100 Then
  2.         ' Set the ball value:
  3.         lblNum(7 - iBallsToMake).Caption = "?"
  4.         GoTo one_less
  5.    End If
  6.  


Al entrar en el proceso timer se establece cada vez a iTryAgainCounter =0 pero como es posible que llegue a 100? sencillo

si se cumple

Código
  1. Val(lblNum(i).Caption) = iNewNum
  2.  

Es decir el valor de lbl(i)Num = iNewNum se le sumara uno YYY retrocese a la marca/etiqueta try_again

Código
  1.    Dim iNewNum As Integer
  2.    Dim i As Integer
  3.    Dim iTryAgainCounter As Integer
  4.  
  5.    iTryAgainCounter = 0
  6.  
  7. try_again:  '<-------Aquì
  8.  
  9.    ' Avoid hand up with max ball 2 and 7 balls
  10.  

P.D.: si me equivoque en alguna explicaciòn disculpa pero tengo sueo Y NO USAS GESHI para simplificar la Lectura del CODIGO.

Usa:

Código:
[code=vb ] 
Codeigo Visual Basic 6
[/code ]
Obviamente sin espacios en las etiquetas

P.S.: disculpa si no lo expliue bien o me salte unas cosas pero son mas que deducibles si revisas bien XP, ademàs de que tengo sueño y ya no pienso bien ahorita   >:(

Dulces Lunas!¡.


[/code]


« Última modificación: 3 Octubre 2009, 09:31 am por ░▒▓BlackZeroҖ▓▒░ » En línea

The Dark Shadow is my passion.
iory330

Desconectado Desconectado

Mensajes: 42


Ver Perfil
Re: Ayuda Con Lotto Code
« Respuesta #2 en: 3 Octubre 2009, 19:01 pm »

Hola BlackZero

Gracias x la pronta respuesta, luego d analizar cuidadosamente los codigos pude despejar mis dudas. Sin embargo, aun me keda algo de intriga.... bueno pues yo he hecho un generador de numeros, todo esta "bien" al parecer pero el problema es que cada vez q abro el programa me genera los mismos numeros. Es decir supuestamente la funcion Rnd genera numeros aleatorios pero en realidad no es asi. Ejemplo: Al abrir el programa y Clickeo Generar. ME sale Siempre:


1.  3 0 2 3 1
2.  1 3 0 1 8
3.  9 8 3 4 5

Es un ejemplo. Es por eso que me he detenido en analizar este codigo ya que en este no me da los mismos numeros cada vez q inicio el programa. 
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Ayuda Con Lotto Code
« Respuesta #3 en: 3 Octubre 2009, 21:17 pm »

si solo pasale Randomize
Aquì te dejo la funcion de Random la funcion correcta:

Código
  1. Private Function RANDOM(RangoInicial As Long, RangoFinal As Long) As Long
  2.    Randomize Rnd
  3.    ' // Intercambiamos los valores por si no se insertaron correctamente
  4.    If RangoInicial > RangoFinal Then
  5.        Dim tmp As Long
  6.        tmp = RangoInicial
  7.        RangoInicial = RangoFinal
  8.        RangoFinal = tmp
  9.    End If
  10.    ' // Fin
  11.    RANDOM = (RangoFinal - RangoInicial + 1) * Rnd + RangoInicial
  12. End Function
  13.  

Solo pasale

El numero inicial y el numero final con eso te generara los numeros aleatoriso en dicho rango, si te llegas a equivocar la funcion lo arreglara por ti

Si es mucho aquì te dijo l version reducida:

Código
  1. Round(Rnd * #5) '  // Cambia el 5 Por el numero deseado tomara un rango de 0 a 5
  2. '  // Si deseas numeros desimales quita Round()
  3. ' // Inicia siempre con Randomize () antes de usar Rnd
  4.  

Dulces Lunas!¡.
« Última modificación: 3 Octubre 2009, 22:32 pm por ░▒▓BlackZeroҖ▓▒░ » En línea

The Dark Shadow is my passion.
iory330

Desconectado Desconectado

Mensajes: 42


Ver Perfil
Re: Ayuda Con Lotto Code
« Respuesta #4 en: 3 Octubre 2009, 22:35 pm »

Ya vi el problema vroer era solo agregar otra function como dijiste q era la randomize al momento de cargar el programa.... Se t agradece x tu aporte..


Y sigue asi .. GRacias


Salu2
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda con code en python
Scripting
Ricardo95 3 2,481 Último mensaje 1 Diciembre 2010, 19:34 pm
por Novlucker
ayuda con code python
Hacking
MessageBoxA 1 2,859 Último mensaje 25 Junio 2013, 03:52 am
por engel lex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines