• Jueves 25 de Abril de 2024, 03:55

Autor Tema:  Este codigo me genera un Error  (Leído 1988 veces)

PedroM

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Este codigo me genera un Error
« en: Jueves 19 de Agosto de 2010, 01:08 »
0
Buenas comunidad, tengo un problema, estoy haciendo un programa tipo juego alzar y me esta generando un error y no se como solucionar eso, soy algo novato en esto del vb, apenas tengo 4 dias viendo clases y se me presento eso dejo el codigo y la parte donde se genera el error.
Citar
Option Explicit
Dim x, y As Integer

Private Sub cmdComenzar_Click()
    x = CInt(Rnd() * (9 - 1) + 1)
End Sub

Private Sub cmdComparar_Click()
    txty = y
    If x > y Then MsgBox " Intente de nuevo el numero es Mayor"
    If x < y Then MsgBox " Intente de nuevo el numero es Memor"
    else x = y Then MsgBox "Enhorabuena aceptaste vuelve a jugar"
   
 
End Sub

Private Sub cmdLimpiar_Click()
    txty = Empty
    txty.SetFocus
End Sub

Private Sub cmdSalir_Click()
    End
End Sub

Private Sub Form_Activate()
    Randomize
    cmdLimpiar.Enabled = False
    cmdComparar.Enabled = False
End Sub
Private Sub txty_Change()
    cmdLimpiar.Enabled = True
    cmdComparar.Enabled = True
End Sub
[/b]

Jimbenit

  • Miembro MUY activo
  • ***
  • Mensajes: 269
  • Nacionalidad: co
    • Ver Perfil
    • http://ingenieriacivil.foroactivo.com
Re: Este codigo me genera un Error
« Respuesta #1 en: Jueves 19 de Agosto de 2010, 18:02 »
0
Lee las indicaciones en el siguiente codigo

Código: Visual Basic
  1. Option Explicit
  2. Dim x, y As Integer     '<---- Aqui "x" es variant y "y" es Integer. Si quieres decir que las dos son Integer, haz asi: Dim x as integer, y as integer
  3.  
  4. Private Sub cmdComenzar_Click()
  5. x = CInt(Rnd() * (9 - 1) + 1)
  6. End Sub
  7.  
  8. Private Sub cmdComparar_Click()
  9. txty = y                    '<--- inicialmente "y" vale cero (0), el valor en el txty es el que el usuario digita pero éste es borrado por el valor de y = 0 (aqui hay un error de tu logica). Si yo fuera tu, yo haria en esta linea: y = txty
  10. If x > y Then MsgBox " Intente de nuevo el numero es Mayor"
  11. If x < y Then MsgBox " Intente de nuevo el numero es Memor"
  12. else x = y Then MsgBox "Enhorabuena aceptaste vuelve a jugar"     '<---  Error. Comando Else de una sola linea? y que incluye una condicion? (No confundas con el "Elseif"), te recomiendo estudiar mas el if ... then .... else... [end if]
  13.  
  14.  
  15. End Sub
  16.  
  17. Private Sub cmdLimpiar_Click()
  18. txty = Empty
  19. txty.SetFocus
  20. End Sub
  21.  
  22.  
  23.  
  24. Private Sub Form_Activate()
  25. Randomize
  26. cmdLimpiar.Enabled = False
  27. cmdComparar.Enabled = False
  28. End Sub
  29. Private Sub txty_Change()
  30. cmdLimpiar.Enabled = True
  31. cmdComparar.Enabled = True
  32. End Sub
  33.  
  34.  


Yo quiero mucho a Toph ---> Mi Web]http://ingenieriacivil.foroactivo.com[/url]

PedroM

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: Este codigo me genera un Error
« Respuesta #2 en: Viernes 20 de Agosto de 2010, 06:48 »
0
Si amigo despues revisando me di cuenta que formule mal el Y=txt eso lo cambie luego y tambien puede hacer lo del if. ya me corri y quedo al pelo muchas gracias!