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 :

Calcul erroné !


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 257
    Par défaut Calcul erroné !
    J'ai un pb. A chaque fois que je saisi un montant au niveau du champ "montant avancé" le calcul automatique des autres champs est juste (txttotalrea, txtmontantpaye et txtresteapayer). Mais quand j'efface le contenu du champ txtmontantavance, le calcul des autres champs est incorrect
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Dim mc As [Decimal] = CDec(Txtmontantc.Text)
                Dim total As [Decimal] = CDec(Txttotalrea.Text)
                Dim ma As [Decimal] = CDec(Txtmontantavance.Text)
                Dim var As [Decimal]
                If Txtmontantavance.Text = "" Then
                    Exit Sub
                    Txtmontantpaye.Text = CDec(Txttotalrea.Text)
                    Txtresteapayer.Text = CDec(Txtmontantc.Text) - CDec(Txttotalrea.Text)
                Else
                    var = total + ma
                    Txtmontantpaye.Text = total + ma
                    Txtresteapayer.Text = mc - var
                End If

  2. #2
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 197
    Par défaut
    tu sais ce que fais Exit Sub ?
    il sort de la sub

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    If Txtmontantavance.Text = "" Then
                    Exit Sub
                    Txtmontantpaye.Text = CDec(Txttotalrea.Text)
                    Txtresteapayer.Text = CDec(Txtmontantc.Text) - CDec(Txttotalrea.Text)
                Else
                    var = total + ma
                    Txtmontantpaye.Text = total + ma
                    Txtresteapayer.Text = mc - var
                End If
    donc tout ce qui est après n'est pas exécuté !!!


    tu devrais quand meme lire un tuto dans la partie algorythme des tutoriels (pas dans .net)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 257
    Par défaut
    C'était une faute de frappe . J'ai enlevé le exit sub et le calcul est tjrs erroné

  4. #4
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 197
    Par défaut
    erroné dans le sens 5+3 = 9 au lieu de 8
    ou alors tu voudrais que 5 = 8 ?
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 257
    Par défaut
    erroné dans le sens 5+3=9

  6. #6
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 197
    Par défaut
    c'est impossible, vs sait compter ...
    c'est ton code qui doit etre faux
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  7. #7
    Membre Expert
    Avatar de Aspic
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    3 905
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2005
    Messages : 3 905
    Par défaut
    Citation Envoyé par loverdev
    J'ai un pb. A chaque fois que je saisi un montant au niveau du champ "montant avancé" le calcul automatique des autres champs est juste (txttotalrea, txtmontantpaye et txtresteapayer). Mais quand j'efface le contenu du champ txtmontantavance, le calcul des autres champs est incorrect
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Dim mc As [Decimal] = CDec(Txtmontantc.Text)
                Dim total As [Decimal] = CDec(Txttotalrea.Text)
                Dim ma As [Decimal] = CDec(Txtmontantavance.Text)
                Dim var As [Decimal]
                If Txtmontantavance.Text = "" Then
                    Exit Sub
                    Txtmontantpaye.Text = CDec(Txttotalrea.Text)
                    Txtresteapayer.Text = CDec(Txtmontantc.Text) - CDec(Txttotalrea.Text)
                Else
                    var = total + ma
                    Txtmontantpaye.Text = total + ma
                    Txtresteapayer.Text = mc - var
                End If
    Ca sens le probleme avec le "Exit Sub"
    Mets des espions pour voir quelle ligne exactement plante !
    Qui ne tente rien n'a rien !
    Ce qui ne nous tue pas nous rends plus fort !!
    Mon projet ZELDA en C++/Allegro
    http://www.tutoworld.com - Le Forum -
    Mes ressources Dotnet (cours, sources, tutos)
    --------------------------------------------
    + + =

    Ne pas oublier le Tag !

  8. #8
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 257
    Par défaut
    J'ai enlevé le exit sub mais ca ne marche toujours pas

  9. #9
    Membre Expert
    Avatar de Aspic
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2005
    Messages
    3 905
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2005
    Messages : 3 905
    Par défaut
    Dans quelle procédure est inseré le code qui tu nous as donné ?
    Qui ne tente rien n'a rien !
    Ce qui ne nous tue pas nous rends plus fort !!
    Mon projet ZELDA en C++/Allegro
    http://www.tutoworld.com - Le Forum -
    Mes ressources Dotnet (cours, sources, tutos)
    --------------------------------------------
    + + =

    Ne pas oublier le Tag !

  10. #10
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 257
    Par défaut
    si je sélectionne le checkbox "optoui" le libellé et le textbox de "montant avancé" apparaît sinon il disparaît dans le cas de sélection de "optnon" et il ya réinitialisation des valeurs des montants "txttotalrea", "txtmontantpaye" et "txtresteapayer".
    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
     
     Private Sub Txtmontantavance_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txtmontantavance.TextChanged
            If annulation = True Then Exit Sub
            Txtmontantavance.Text = Txtmontantavance.Text.Replace(".", ",")
            Txtmontantavance.Select(Txtmontantavance.Text.Length, 0)
            Try
                If Txtmontantavance.Text = "" Then
                    Dim mc As [Decimal] = CDec(Txtmontantc.Text)
                    Dim total As [Decimal] = CDec(Txttotalrea.Text)
                    Dim ma As [Decimal] = CDec(Txtmontantavance.Text)
                    Txtmontantpaye.Text = CDec(Txttotalrea.Text)
                    Txtresteapayer.Text = CDec(Txtmontantc.Text) - CDec(Txttotalrea.Text)
                Else
                    Dim mc As [Decimal] = CDec(Txtmontantc.Text)
                    Dim total As [Decimal] = CDec(Txttotalrea.Text)
                    Dim ma As [Decimal] = CDec(Txtmontantavance.Text)
                    Dim var As [Decimal]
                    var = total + ma
                    Txtmontantpaye.Text = total + ma
                    Txtresteapayer.Text = mc - (total + ma)
                End If
            Catch ex As Exception
     
            End Try
            If IsNumeric(Txtmontantavance.Text) Then
                Exit Sub
            ElseIf (Txtmontantavance.Text) = "" Then
                Exit Sub
            Else
                MsgBox("Vous devez saisir une valeur monétaire", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
                Txtmontantavance.Text = ""
            End If
        End Sub
    et voici le code des checkbox :
    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
     
    Private Sub Optoui_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Optoui.CheckedChanged
            Label14.Visible = True
            Txtmontantavance.Visible = True
            'Txtmontantavance.Text = ""
        End Sub
     
        Private Sub Optnon_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Optnon.CheckedChanged
            Label14.Visible = False
            Txtmontantavance.Visible = False
            If Txtmontantavance.Text <> "" Then
                Dim total As [Decimal] = CDec(Txttotalrea.Text)
                Dim mc As [Decimal] = CDec(Txtmontantc.Text)
                Dim ma As [Decimal] = CDec(Txtmontantavance.Text)
                Txttotalrea.Text = total - ma
                Txtmontantpaye.Text = CDec(Txttotalrea.Text)
                Txtresteapayer.Text = mc - CDec(Txttotalrea.Text)
            End If
            If Txtmontantavance.Text = "" Then
                Dim var As [Decimal]
                Dim total As [Decimal] = CDec(Txttotalrea.Text)
                Dim mc As [Decimal] = CDec(Txtmontantc.Text)
                Txttotalrea.Text = total
                Txtmontantpaye.Text = total
                var = CDec(Txttotalrea.Text)
                Txtresteapayer.Text = mc - var
            End If
        End Sub

  11. #11
    Membre confirmé
    Inscrit en
    Mai 2007
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 257
    Par défaut
    SVP aidez moi je suis bloqué

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

Discussions similaires

  1. Calcul erroné en pied d'état
    Par P'tit aviateur dans le forum IHM
    Réponses: 2
    Dernier message: 10/03/2009, 13h47
  2. Problème calcul erroné avec sum()
    Par mouatte dans le forum Requêtes
    Réponses: 25
    Dernier message: 15/12/2008, 12h58
  3. Calcul erroné d'un carré dans un longint
    Par paskal++ dans le forum Langage
    Réponses: 6
    Dernier message: 28/11/2008, 13h32
  4. Résultat de calcul erroné
    Par TheBuzz dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 23/06/2008, 08h00
  5. Réponses: 0
    Dernier message: 11/11/2007, 07h03

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