IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

comparaison d'une valeur


Sujet :

VB.NET

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 2
    Par défaut comparaison d'une valeur
    j'ai quelques soucis avec mon programme je cherche à comparer une valeur qui selon ce qu'elle en donne une autre correspondante

    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
    41
    42
    43
    44
    45
    46
    47
    48
    49
     If Form6.TextBox10.Text <= 0.036 Then
     
                Form6.TextBox14.Text = "3,75"
     
            ElseIf Form6.TextBox10.Text >= 0.036 And Form6.TextBox10.Text < 0.035 Then
     
                Form6.TextBox14.Text = "4"
     
            ElseIf Form6.TextBox10.Text >= 0.035 And Form6.TextBox10.Text < 0.0335 Then
     
                Form6.TextBox14.Text = "4.25"
     
            ElseIf Form6.TextBox10.Text >= 0.0335 And Form6.TextBox10.Text < 0.032 Then
     
                Form6.TextBox14.Text = "4.5"
     
            ElseIf Form6.TextBox10.Text >= 0.032 And Form6.TextBox10.Text < 0.0315 Then
     
                Form6.TextBox14.Text = "4.75"
     
            ElseIf Form6.TextBox10.Text >= 0.0315 And Form6.TextBox10.Text < 0.029 Then
     
                Form6.TextBox14.Text = "5"
     
            ElseIf Form6.TextBox10.Text >= 0.029 And Form6.TextBox10.Text < 0.028 Then
     
                Form6.TextBox14.Text = "5.25"
     
            ElseIf Form6.TextBox10.Text >= 0.028 And Form6.TextBox10.Text < 0.027 Then
     
                Form6.TextBox14.Text = "5.5"
     
            ElseIf Form6.TextBox10.Text >= 0.027 And Form6.TextBox10.Text < 0.026 Then
     
                Form6.TextBox14.Text = "5.75"
     
     
            ElseIf Form6.TextBox10.Text >= 0.026 And Form6.TextBox10.Text < 0.025 Then
     
                Form6.TextBox14.Text = "6"
     
            ElseIf Form6.TextBox10.Text >= 0.025 And Form6.TextBox10.Text < 0.023 Then
     
                Form6.TextBox14.Text = "6.25"
     
            ElseIf Form6.TextBox10.Text >= 0.023 Then
     
                Form6.TextBox14.Text = "6.5"
            End If
    Le problème que quand la valeur est donnée il me donne soit 3.75 ou 6.5 en correspondance. Je tiens à précisé que je suis un gros débutant

  2. #2
    Membre Expert Avatar de LaChips
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    1 109
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 109
    Par défaut
    Bonjour,
    Essayez avec ce code :

    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
     
            Dim input As Integer = Integer.Parse(Form6.TextBox10.Text)
            Dim output As Integer
     
            If input <= 0.036 Then
                output = 3.75
            ElseIf input < 0.035 Then
                output = 4
            ElseIf input < 0.0335 Then
                output = 4.25
            ElseIf input < 0.032 Then
                output = 4.5
            ElseIf input < 0.0315 Then
                output = 4.75
    ......
            End If

  3. #3
    Membre Expert Avatar de OhMonBato
    Homme Profil pro
    Inscrit en
    Mars 2007
    Messages
    2 660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 2 660
    Par défaut
    Il me semble qu'il y a une inversion sur les signes < et > , si j'ai bien compris (pas sûr...) ton code serait plutôt :

    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
      If Form6.TextBox10.Text >= 0.036 Then
                Form6.TextBox14.Text = "3.75"
            ElseIf Form6.TextBox10.Text <= 0.036 And Form6.TextBox10.Text > 0.035 Then
                Form6.TextBox14.Text = "4"
            ElseIf Form6.TextBox10.Text <= 0.035 And Form6.TextBox10.Text > 0.0335 Then
                Form6.TextBox14.Text = "4.25"
            ElseIf Form6.TextBox10.Text <= 0.0335 And Form6.TextBox10.Text > 0.032 Then
                Form6.TextBox14.Text = "4.5"
            ElseIf Form6.TextBox10.Text <= 0.032 And Form6.TextBox10.Text > 0.0315 Then
                Form6.TextBox14.Text = "4.75"
            ElseIf Form6.TextBox10.Text <= 0.0315 And Form6.TextBox10.Text > 0.029 Then
                Form6.TextBox14.Text = "5"
            ElseIf Form6.TextBox10.Text <= 0.029 And Form6.TextBox10.Text > 0.028 Then
                Form6.TextBox14.Text = "5.25"
            ElseIf Form6.TextBox10.Text <= 0.028 And Form6.TextBox10.Text > 0.027 Then
                Form6.TextBox14.Text = "5.5"
            ElseIf Form6.TextBox10.Text <= 0.027 And Form6.TextBox10.Text > 0.026 Then
                Form6.TextBox14.Text = "5.75"
            ElseIf Form6.TextBox10.Text <= 0.026 And Form6.TextBox10.Text > 0.025 Then
                Form6.TextBox14.Text = "6"
            ElseIf Form6.TextBox10.Text <= 0.025 And Form6.TextBox10.Text > 0.023 Then
                Form6.TextBox14.Text = "6.25"
            ElseIf Form6.TextBox10.Text <= 0.023 Then
                Form6.TextBox14.Text = "6.5"
            End If
    Mais tu pourrais le simplifier et le rendre plus lisible de cette manière :

    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
      If Form6.TextBox10.Text <= 0.023 Then
                Form6.TextBox14.Text = "6.5"
            ElseIf Form6.TextBox10.Text <= 0.025 Then
                Form6.TextBox14.Text = "6.25"
            ElseIf Form6.TextBox10.Text <= 0.026 Then
                Form6.TextBox14.Text = "6"
            ElseIf Form6.TextBox10.Text <= 0.027 Then
                Form6.TextBox14.Text = "5.75"
            ElseIf Form6.TextBox10.Text <= 0.028 Then
                Form6.TextBox14.Text = "5.5"
            ElseIf Form6.TextBox10.Text <= 0.029 Then
                Form6.TextBox14.Text = "5.25"
            ElseIf Form6.TextBox10.Text <= 0.0315 Then
                Form6.TextBox14.Text = "5"
            ElseIf Form6.TextBox10.Text <= 0.032 Then
                Form6.TextBox14.Text = "4.75"
            ElseIf Form6.TextBox10.Text <= 0.0335 Then
                Form6.TextBox14.Text = "4.5"
            ElseIf Form6.TextBox10.Text <= 0.035 Then
                Form6.TextBox14.Text = "4.25"
            ElseIf Form6.TextBox10.Text <= 0.036 Then
                Form6.TextBox14.Text = "4"
            Else
                Form6.TextBox14.Text = "3.75"
            End If
    Sauf erreur de ma part, il me semble qu'avec le code de LaChips, si ta valeur vaut 0.032 par exemple, le premier test sera vrai et tu obtiendras 3.75.
    Si j'ai mal compris ton text en tout cas tes tests pour le moment ne sonrt JAMAIS bons, une valeur ne peut pas être à la fois >= 0.036 ET < 0.035

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 2
    Par défaut
    ca y est j'ai trouvé oui c'était bien une inversion je vous remercie beaucoup de votre aide

  5. #5
    Membre Expert Avatar de LaChips
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    1 109
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 109
    Par défaut
    Ah oui effectivement, j'ai pas fait attention à çà, il faut inverser les lignes.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [AC-2000] Comparaison d'une valeur dispo dans une ZDL pendant la saisie
    Par Nerva dans le forum VBA Access
    Réponses: 23
    Dernier message: 01/11/2010, 11h53
  2. Réponses: 2
    Dernier message: 20/11/2009, 15h13
  3. hash comparaison d'une valeur vs le reste
    Par Jasmine80 dans le forum Langage
    Réponses: 4
    Dernier message: 14/11/2008, 08h43
  4. Comparaison d'une valeur pour trouver la plus proche
    Par Falcdyr dans le forum VBA Access
    Réponses: 4
    Dernier message: 16/04/2008, 17h10
  5. Comparaison d'une valeur à une liste
    Par Pietro_L dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 11/03/2008, 15h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo