Non prise en compte de mon code
Bonjour,
je pense que la solution ne doit pas être difficile, mais là, je dois relire ma faute à chaque fois !!
Mon programme est un test de nombre entre 1 et 100 rentré par l'utilisateur !!
Voici mon [IMG]userform[/IMG].
Les 2 problèmes sont les suivants:
1) il n'y a pas de prise en compte de la partie ou je teste si le nombre entré est compris entre 1 et 100.
2) au niveau de la mise à jour des bornes; à chaque saisie, le programme réinitialise la borne sup et la borne inf !! donc l'intérêt est limité...
Merci de votre aide !!
Code:
1 2 3 4 5 6 7 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
'déclarer une variable globale au userform
Dim compteurEssai As Integer
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub Label1_Click()
Label1.TextAlign = fmTextAlignCenter
End Sub
Private Sub TextBox1_Change()
TextBox1.TextAlign = fmTextAlignCenter
End Sub
Private Sub temps_click()
'temps.Caption = tps
End Sub
Private Sub Valider_Click()
Dim intRetour As Integer
If compteurEssai = 11 Then
Label1.Caption = ("Perdu")
Exit Sub
End If
intRetour = hasard1
Select Case hasard1
Case 1
Label1.Caption = "Bravo"
Case 2
Label1.Caption = ("C'est trop grand !")
Case 3
Label1.Caption = ("C'est trop petit!")
End Select
compteurEssai = compteurEssai + 1
End Sub
'1 trouvé
'2 trop grand
'3 trop petit
Function hasard1() As Integer
Dim secret As Integer
Dim cherche As Integer
Dim fin As Integer
Dim inf As Integer
Dim sup As Integer
Dim ninf As Integer
Dim nsup As Integer
Randomize
secret = Int(100 * Rnd) + 1
ninf = 1
nsup = 100
Max = 2
cherche = TextBox1.Text
If cherche > 100 And cherche < 0 Then
inter.Caption = "Erreur de saisie"
Else
If cherche = secret Then
hasard1 = 1
Else
If cherche > secret Then
hasard1 = 2
nsup = cherche
inter.Caption = ("Nombre = [" & ninf & " ; " & nsup & "]")
Else
hasard1 = 3
ninf = cherche
inter.Caption = ("Nombre = [" & ninf & " ; " & nsup & "]")
End If
End If
End If
End Function |