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

VBA Word Discussion :

2 décimales obligatoires dans une text box


Sujet :

VBA Word

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 45
    Points : 14
    Points
    14
    Par défaut 2 décimales obligatoires dans une text box
    Bonjour,

    Savez vous rendre obligatoire le nombre de décimales dans des textbox :

    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
     
     
    Private Sub CommandButton1_Click()
     
    TextBox1.Value = Replace(TextBox1.Value, ".", ",")
    TextBox2.Value = Replace(TextBox2.Value, ".", ",")
    TextBox3.Value = Replace(TextBox3.Value, ".", ",")
    TextBox4.Value = Replace(TextBox4.Value, ".", ",")
    TextBox5.Value = Replace(TextBox5.Value, ".", ",")
     
    If TextBox1 <> "" Then
    val1 = Format(TextBox1.Value, "#,##0.00") * 1
    End If
     
    If TextBox2 <> "" Then
    val2 = Format(TextBox2.Value, "#,##0.00") * 1
    End If
     
    If TextBox3 <> "" Then
    val3 = Format(TextBox3.Value, "#,##0.00") * 1
    End If
     
    If TextBox4 <> "" Then
    val4 = Format(TextBox4.Value, "#,##0.00") * 1
    End If
     
    If TextBox5 <> "" Then
    val5 = Format(TextBox5.Value, "#,##0.00") * 1
    End If
     
    total = val1 + val2 + val3 + val4 + val5
    TextBox8.Value = Format(total, "#,##0.00") * 1
     
    facteur1 = Format(TextBox6.Value, "#,###0.000") * 1
    facteur2 = Format(TextBox7.Value, "#,###0.000") * 1
     
    TextBox9.Value = Format(facteur1 * total, "#,##0.00") * 1
    TextBox10.Value = Format(facteur2 * total, "#,##0.00") * 1
    TextBox11.Value = Format((facteur1 + facteur2) * total, "#,##0.00") * 1
     
    End Sub
    Merci pour votre aide

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Avril 2011
    Messages
    45
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2011
    Messages : 45
    Points : 14
    Points
    14
    Par défaut problème ordre commande
    Problème résolu : en fait il faut faire la calcul puis afficher le chiffre arrondi :

    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
     
     
    Private Sub CommandButton1_Click()
     
    TextBox1.Value = Replace(TextBox1.Value, ".", ",")
    TextBox2.Value = Replace(TextBox2.Value, ".", ",")
    TextBox3.Value = Replace(TextBox3.Value, ".", ",")
    TextBox4.Value = Replace(TextBox4.Value, ".", ",")
    TextBox5.Value = Replace(TextBox5.Value, ".", ",")
     
    If TextBox1 <> "" Then
    val1 = TextBox1.Value * 1
    End If
     
    If TextBox2 <> "" Then
    val2 = TextBox2.Value * 1
    End If
     
    If TextBox3 <> "" Then
    val3 = TextBox3.Value * 1
    End If
     
    If TextBox4 <> "" Then
    val4 = TextBox4.Value * 1
    End If
     
    If TextBox5 <> "" Then
    val5 = TextBox5.Value * 1
    End If
     
    total = val1 + val2 + val3 + val4 + val5
    TextBox8.Value = Format(total, "#,##0.00")
     
    facteur1 = Format(TextBox6.Value, "#,###0.000") * 1
    facteur2 = Format(TextBox7.Value, "#,###0.000") * 1
     
    valeur1 = facteur1 * total
    TextBox9.Value = Format(valeur1, "#,##0.00")
     
    valeur2 = facteur2 * total
    TextBox10.Value = Format(valeur2, "#,##0.00")
     
    resultat = (facteur1 + facteur2) * total
    TextBox11.Value = Format(resultat, "#,##0.00")
     
    End Sub

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

Discussions similaires

  1. Avoir la possibilité de saisir des caractères spéciaux dans une text-box
    Par Vincent32 dans le forum Macros et VBA Excel
    Réponses: 15
    Dernier message: 08/11/2010, 15h50
  2. Ecrire dans une text Box avec une mouseMove
    Par popsmelove dans le forum Macros et VBA Excel
    Réponses: 7
    Dernier message: 03/03/2008, 14h00
  3. requete select dans une text box
    Par galaad666 dans le forum IHM
    Réponses: 5
    Dernier message: 29/11/2006, 13h55
  4. Réponses: 6
    Dernier message: 14/02/2006, 20h53

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