Else ne fonctionne pas avec If = Arg1 or Arg 2 or Arg3

pacoako

XLDnaute Occasionnel
Bonjour à tous!

Je me demandais pourquoi mon Else ne fonctionnait pas sur un If = Arg1 or Arg2 or Arg3...

Voici mon code

Code:
Option Explicit
Dim SEQPREC As Integer
Dim SEQSUIV As Integer

Private Sub CommandButton1_Click()

If TextBox1 = "25" Or "33" Or "41" Or "58" Or "66" Or "74" Or "82" Or "90" Or "17" Then

    If TextBox1 = "33" Then
    SEQPREC = "25"
    SEQSUIV = "41"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "41" Then
    SEQPREC = "33"
    SEQSUIV = "59"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "58" Then
    SEQPREC = "41"
    SEQSUIV = "65"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "66" Then
    SEQPREC = "54"
    SEQSUIV = "74"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "74" Then
    SEQPREC = "66"
    SEQSUIV = "82"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "82" Then
    SEQPREC = "74"
    SEQSUIV = "90"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "90" Then
    SEQPREC = "82"
    SEQSUIV = "17"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "17" Then
    SEQPREC = "90"
    SEQSUIV = "34"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "25" Then
    SEQPREC = "17"
    SEQSUIV = "43"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If

Else
MsgBox "Cette séquence est impossible."
End If

Merci d'avance pour vos réflexions & bonne soirée!
 

skoobi

XLDnaute Barbatruc
Re : Else ne fonctionne pas avec If = Arg1 or Arg 2 or Arg3

Bonsoir pacoako,

ce cas est tout désigné pour utiliser Select Case:
Code:
Option Explicit
Dim SEQPREC As Integer
Dim SEQSUIV As Integer

Private Sub CommandButton1_Click()
[B][COLOR=Blue]Select Case TextBox1
Case "25", "33", "41", "58", "66", "74", "82", "90", "17"[/COLOR][/B]

    If TextBox1 = "33" Then
    SEQPREC = "25"
    SEQSUIV = "41"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "41" Then
    SEQPREC = "33"
    SEQSUIV = "59"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "58" Then
    SEQPREC = "41"
    SEQSUIV = "65"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "66" Then
    SEQPREC = "54"
    SEQSUIV = "74"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "74" Then
    SEQPREC = "66"
    SEQSUIV = "82"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "82" Then
    SEQPREC = "74"
    SEQSUIV = "90"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "90" Then
    SEQPREC = "82"
    SEQSUIV = "17"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "17" Then
    SEQPREC = "90"
    SEQSUIV = "34"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If
    If TextBox1 = "25" Then
    SEQPREC = "17"
    SEQSUIV = "43"
    MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
    End If

[COLOR=Blue][B]Case Else[/B][/COLOR]
MsgBox "Cette séquence est impossible."
[B][COLOR=Blue]End Select[/COLOR][/B]
 

ledzepfred

XLDnaute Impliqué
Re : Else ne fonctionne pas avec If = Arg1 or Arg 2 or Arg3

bonsoir pacoako,

cela fonctionnerait mieux comme ceci :

Code:
If textbox1 = "25" Or [COLOR="Red"]textbox1 =[/COLOR]"33" Or [COLOR="Red"]textbox1 =[/COLOR]"41" Or [COLOR="Red"]textbox1 =[/COLOR]"58" Or [COLOR="Red"]textbox1 =[/COLOR]"66" Or [COLOR="Red"]textbox1 =[/COLOR]"74" Or [COLOR="Red"]textbox1 =[/COLOR]"82" Or [COLOR="Red"]textbox1 =[/COLOR]"90" Or [COLOR="Red"]textbox1 =[/COLOR]"17" Then

Mais c'est un peu lourd, ce serait mieux d'utiliser select case... end case

A testé...
Code:
Option Explicit
Dim SEQPREC As Integer
Dim SEQSUIV As Integer

Private Sub CommandButton1_Click()
SEQPREC = 0
Select Case textbox1.Value
    Case "17"
        SEQPREC = 90: SEQSUIV = 34
    Case "25"
        SEQPREC = 17: SEQSUIV = 43
    Case "33"
        SEQPREC = 25: SEQSUIV = 41
    Case "41"
        SEQPREC = 33: SEQSUIV = 59
    Case "58"
        SEQPREC = 41: SEQSUIV = 65
    Case "66"
        SEQPREC = 54: SEQSUIV = 74
    Case "74"
        SEQPREC = 66: SEQSUIV = 82
    Case "82"
        SEQPREC = 74: SEQSUIV = 90
    Case "90"
        SEQPREC = 82: SEQSUIV = 17
End Select

If SEQPREC <> 0 Then
MsgBox "La séquence précédente est " & SEQPREC & Chr(13) & "La séquence suivante est " & SEQSUIV
Else
MsgBox "Cette séquence est impossible."
End If
Ai supprimé les guillemets pour la définition de SEQPREC et SECSUIV sachant que ce sont des variables de type Integer
a+

edit : salut Skoobi ai pas rafraichi!
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 177
Messages
2 085 976
Membres
103 076
dernier inscrit
LoneWolf90