hola estoy empezando con lo basico en vb y me interezo un programa que vi en c
donde el programa generaba un numero al azar y el usuario tenia que introducir un numero cualquiera sin saber que numero era el que tenia que adivinar... les dejo un screen y el code
(http://img519.imageshack.us/img519/3248/dibujo2tv8.th.png)
Private Sub Command1_Click()
Dim numero As Integer
Dim scanf As Integer
Randomize Timer
numero = Rnd
numero = Rnd * 10
numero = CInt(A)
scanf = Val(Text1)
If scanf = numero Then
Label1.Caption = "acertaste" & numero
Else
If scanf < numero Then
Label1.Caption = "mas alto" & numero
Else
If scanf > numero Then
Label1.Caption = "mas bajo" & numero
Else
Label1.Caption = "que carajo escribiste¿? " & numero
End If
End If
End If
End Sub
Prueba asi...
Option Explicit
Private Sub Command1_Click()
Dim Numero As Integer
Randomize
Numero = Rnd * 10
If Text1.Text = "" Then Exit Sub
If Val(Text1.Text) = Numero Then
MsgBox "acertaste! el numero era: '" & Numero & "'"
Else
MsgBox "fracasaste! el numero era: '" & Numero & "'"
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'Este procedimiento permite que se incerten, solo las teclas deseadas usando la Ascii.
If KeyAscii <> 8 Then 'Verifica si se presionó las teclas de direcciones.
If KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End If
End Sub
Saludos!
muchas gracias aca encontre otra forma de usar el random que tambien esta buena ...
Private Sub Command1_Click()
numero = Int((Rnd * 10) + 1)
If Text1 = "" Then
Label1.Caption = "no has introducido ningun numero " & numero
Else
If Text1 = numero Then
Label1.Caption = "acertaste " & numero
Else
If Text1 < numero Then
Label1.Caption = "mas alto " & numero
Else
If Text1 > numero Then
Label1.Caption = "mas bajo " & numero
Else
Label1.Caption = "que carajo escribiste¿? " & numero
End If
End If
End If
End If
End Sub