Bonjour,
voilà j'ai ce code qui fonctionne très bien (il doit permettre à l'utilisateur de trouver un nombre entre 1 et 100)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Option Explicit Sub hasard1() 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 Dim max As Integer Randomize secret = Int(100 * Rnd) + 1 ninf = 1 nsup = 100 max = 2 cherche = InputBox("Essai n°1" & " Intervalle: [" & ninf & ", " & nsup & "]. " & "Entrer un nombre:") Do If cherche = secret Then fin = MsgBox("Vous avez gagné !!") Else If cherche > secret Then sup = MsgBox("C'est trop grand !") nsup = cherche cherche = InputBox("Essai n°" & max & " Intervalle: [" & ninf & ", " & nsup & "]. " & "Entrer un nombre:") max = max + 1 Else inf = MsgBox("C'est trop petit !") ninf = cherche cherche = InputBox("Essai n°" & max & " Intervalle: [" & ninf & ", " & nsup & "]. " & "Entrer un nombre:") max = max + 1 End If End If Loop While cherche <> secret And max <> 11 If max = 11 Then MsgBox "Perdu" Else MsgBox "bravo" End If End Sub
J'aimerais maintenant évoluer un peuet passer à l'utilisation des UserForm !! Mais je ne sais pas si je peux utiliser une partie du code précédent ou bien tout reprogrammer...
![]()
Partager