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 :

Pas si facile les additions en VB.Net


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2009
    Messages
    106
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2009
    Messages : 106
    Par défaut Pas si facile les additions en VB.Net
    Bonjour,
    J'ai un formulaire que j'utilise pour entrer les quantités de la monnaie se trouvant dans un tiroir-caisse, il y a 15 différentes dénominations comme vous le voyez sur l'image avec le nom des 15 champs à additionner.
    Lorsque je clique sur un des 15 boutons, tout se recalcule automatiquement.

    Voici l'image et c'est suivi du code pour ce formulaire.
    Merci
    Claude du Québec, Canada

    Nom : Currency management.jpg
Affichages : 233
Taille : 178,2 Ko
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    Public Class CurrencyManagement
        Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
            Me.Close()
        End Sub
     
        Private Sub BtnMaximize_Click(sender As Object, e As EventArgs) Handles BtnMaximize.Click
            WindowState = FormWindowState.Maximized
            Me.BtnNormal.Visible = True
            Me.BtnMaximize.Visible=false
        End Sub
     
        Private Sub BtnNormal_Click(sender As Object, e As EventArgs) Handles BtnNormal.Click
            WindowState = FormWindowState.Normal
            Me.BtnMaximize.Visible = True
            Me.BtnNormal.Visible=False
        End Sub
     
        Private Sub BtnMinimize_Click(sender As Object, e As EventArgs) Handles BtnMinimize.Click
            WindowState = FormWindowState.Minimized
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Label1.Text = "0" Then
                Label1.Text = "1"
            Else 
                Label1.Text = Label1.Text + "1"
            End If
        End Sub
     
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            If Label1.Text = "0" Then
                Label1.Text = "2"
            Else 
                Label1.Text = Label1.Text + "2"
            End If
        End Sub
     
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            If Label1.Text = "0" Then
                Label1.Text = "3"
            Else 
                Label1.Text = Label1.Text + "3"
            End If
        End Sub
     
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            If Label1.Text = "0" Then
                Label1.Text = "4"
            Else 
                Label1.Text = Label1.Text + "4"
            End If
        End Sub
     
        Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
            If Label1.Text = "0" Then
                Label1.Text = "5"
            Else 
                Label1.Text = Label1.Text + "5"
            End If
        End Sub
     
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            If Label1.Text = "0" Then
                Label1.Text = "6"
            Else 
                Label1.Text = Label1.Text + "6"
            End If
        End Sub
     
        Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
            If Label1.Text = "0" Then
                Label1.Text = "7"
            Else 
                Label1.Text = Label1.Text + "7"
            End If
        End Sub
     
        Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
            If Label1.Text = "0" Then
                Label1.Text = "8"
            Else 
                Label1.Text = Label1.Text + "8"
            End If
        End Sub
     
        Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
            If Label1.Text = "0" Then
                Label1.Text = "9"
            Else 
                Label1.Text = Label1.Text + "9"
            End If
        End Sub
     
        Private Sub ButtonC_Click(sender As Object, e As EventArgs) Handles ButtonC.Click
            Label1.Text=""
            'Label2.Text=""
            Label1.Text="0"
        End Sub
     
        Private Sub Button0_Click(sender As Object, e As EventArgs) Handles Button0.Click
            If Label1.Text = "0" Then
                Label1.Text = "0"
            Else 
                Label1.Text = Label1.Text + "0"
            End If
        End Sub
     
        Private Sub Btn100D_Click(sender As Object, e As EventArgs) Handles Btn100D.Click
                Me.Qty100D.Text = Label1.Text
                Label1.Text = "0"
                Text100Value.Text=(Convert.ToInt32(Qty100D.Text)*Convert.ToInt32(Btn100D.Text))
        End Sub
     
     
        Private Sub Btn50D_Click(sender As Object, e As EventArgs) Handles Btn50D.Click
                Me.Qty50D.Text = Label1.Text
                Label1.Text = "0"
                Text50Value.Text=(Convert.ToInt32(Qty50D.Text)*Convert.ToInt32(Btn50D.Text))
        End Sub
        Private Sub Btn20D_Click(sender As Object, e As EventArgs) Handles Btn20D.Click
                Me.Qty20D.Text = Label1.Text
                Label1.Text = "0"
                Text20Value.Text=(Convert.ToInt32(Qty20D.Text)*Convert.ToInt32(Btn20D.Text))
        End Sub
     
        Private Sub Btn10D_Click(sender As Object, e As EventArgs) Handles Btn10D.Click
                Me.Qty10D.Text = Label1.Text
                Label1.Text = "0"
                Text10Value.Text=(Convert.ToInt32(Qty10D.Text)*Convert.ToInt32(Btn10D.Text))
        End Sub
     
        Private Sub Btn5D_Click(sender As Object, e As EventArgs) Handles Btn5D.Click
                Me.Qty5D.Text = Label1.Text
                Label1.Text = "0"
                Text5Value.Text=(Convert.ToInt32(Qty5D.Text)*Convert.ToInt32(Btn5D.Text))
        End Sub
     
        Private Sub Btn2D_Click(sender As Object, e As EventArgs) Handles Btn2D.Click
                Me.Qty2D.Text = Label1.Text
                Label1.Text = "0"
                Text2Value.Text=(Convert.ToInt32(Qty2D.Text)*Convert.ToInt32(Btn2D.Text))
        End Sub
     
        Private Sub Btn1D_Click(sender As Object, e As EventArgs) Handles Btn1D.Click
                Me.Qty1D.Text = Label1.Text
                Label1.Text = "0"
                Text1Value.Text=(Convert.ToInt32(Qty1D.Text)*Convert.ToInt32(Btn1D.Text))
        End Sub
     
        Private Sub Btn25C_Click(sender As Object, e As EventArgs) Handles Btn25C.Click
     
                Me.Qty25C.Text = Label1.Text
                Label1.Text = "0"
                Text25CValue.Text=(Convert.ToInt64(Qty25C.Text)*0.25)
        End Sub
     
        Private Sub Btn10C_Click(sender As Object, e As EventArgs) Handles Btn10C.Click
                Me.Qty10C.Text = Label1.Text
                Label1.Text = "0"
                Text10CValue.Text=(Convert.ToInt32(Qty10C.Text)*0.10)
        End Sub
     
        Private Sub Btn5C_Click(sender As Object, e As EventArgs) Handles Btn5C.Click
                Me.Qty5C.Text = Label1.Text
                Label1.Text = "0"
                Text5CValue.Text=(Convert.ToInt32(Qty5C.Text)*0.05)
        End Sub
     
        Private Sub Btn1C_Click(sender As Object, e As EventArgs) Handles Btn1C.Click
                Me.Qty1C.Text = Label1.Text
                Label1.Text = "0"
                Text1CValue.Text=(Convert.ToInt32(Qty1C.Text)*0.01)
        End Sub
     
        Private Sub Btn25R_Click(sender As Object, e As EventArgs) Handles Btn25R.Click
            Me.Qty25R.Text = Label1.Text
            Label1.Text = "0"
            Text25RValue.Text=(Convert.ToInt32(Qty25R.Text)*Convert.ToInt32(Btn25R.Text))
        End Sub
     
        Private Sub Btn10R_Click(sender As Object, e As EventArgs) Handles Btn10R.Click
            Me.Qty10R.Text = Label1.Text
            Label1.Text = "0"
            Text10RValue.Text=(Convert.ToInt32(Qty10R.Text)*Convert.ToInt32(Btn10R.Text))
         End Sub
     
        Private Sub Btn5R_Click(sender As Object, e As EventArgs) Handles Btn5R.Click
            Me.Qty5R.Text = Label1.Text
            Label1.Text = "0"
            Text5RValue.Text=(Convert.ToInt32(Qty5R.Text)*Convert.ToInt32(Btn5R.Text))
        End Sub
     
        Private Sub Btn1R_Click(sender As Object, e As EventArgs) Handles Btn1R.Click
            Me.Qty1R.Text = Label1.Text
            Label1.Text = "0"
            Text1RValue.Text=(Convert.ToInt32(Qty1R.Text)*0.50)
        End Sub
     
        Private Sub CurrencyManagement_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Qty100D.ReadOnly = True
            Me.Qty50D.ReadOnly = True
            Me.Qty20D.ReadOnly = True
            Me.Qty10D.ReadOnly = True
            Me.Qty5D.ReadOnly = True
            Me.Qty2D.ReadOnly = True
            Me.Qty1D.ReadOnly = True
        End Sub
     
        Private Sub Text100Value_TextChanged(sender As Object, e As EventArgs) Handles Text100Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text100Value.Text.Trim(), value) Then
                Text100Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text50Value_TextChanged(sender As Object, e As EventArgs) Handles Text50Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text50Value.Text.Trim(), value) Then
                Text50Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text20Value_TextChanged(sender As Object, e As EventArgs) Handles Text20Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text20Value.Text.Trim(), value) Then
                Text20Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text10Value_TextChanged(sender As Object, e As EventArgs) Handles Text10Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text10Value.Text.Trim(), value) Then
                Text10Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text5Value_TextChanged(sender As Object, e As EventArgs) Handles Text5Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text5Value.Text.Trim(), value) Then
                Text5Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text2Value_TextChanged(sender As Object, e As EventArgs) Handles Text2Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text2Value.Text.Trim(), value) Then
                Text2Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text1Value_TextChanged(sender As Object, e As EventArgs) Handles Text1Value.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text1Value.Text.Trim(), value) Then
                Text1Value.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text25CValue_TextChanged(sender As Object, e As EventArgs) Handles Text25CValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text25CValue.Text.Trim(), value) Then
                Text25CValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text10CValue_TextChanged(sender As Object, e As EventArgs) Handles Text10CValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text10CValue.Text.Trim(), value) Then
                Text10CValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text5CValue_TextChanged(sender As Object, e As EventArgs) Handles Text5CValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text5CValue.Text.Trim(), value) Then
                Text5CValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text1CValue_TextChanged(sender As Object, e As EventArgs) Handles Text1CValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text1CValue.Text.Trim(), value) Then
                Text1CValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text25RValue_TextChanged(sender As Object, e As EventArgs) Handles Text25RValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text25RValue.Text.Trim(), value) Then
                Text25RValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text10RValue_TextChanged(sender As Object, e As EventArgs) Handles Text10RValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text10RValue.Text.Trim(), value) Then
                Text10RValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text5RValue_TextChanged(sender As Object, e As EventArgs) Handles Text5RValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text5RValue.Text.Trim(), value) Then
                Text5RValue.Text = value.ToString("c")
                End If
        End Sub
     
        Private Sub Text1RValue_TextChanged(sender As Object, e As EventArgs) Handles Text1RValue.TextChanged
            Dim value As Decimal
                If Decimal.TryParse(Text1RValue.Text.Trim(), value) Then
                Text1RValue.Text = value.ToString("c")
                End If
        End Sub
    End Class

  2. #2
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Par défaut
    Bonjour,

    Je ne vois pas de question.

    Pouvez-vous exposer et décrire le problème?

    Merci.

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2009
    Messages
    106
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2009
    Messages : 106
    Par défaut Comment additionner tous les Text???Value
    Bonjour,
    Premièrement merci pour le lien de Dvp.NET je suis en train de l'installer et je vais le lire avec attention. Pour ce qui est de ma question elle devrait être assez simple:
    J'ai dans cet exemple 15 champs qui sont mis à jour lorsqu'un utilisateur choisi une quantité (avec l'aide du clavier numérique) et ensuite clique sur la dénomination, présentement, tout fonctionne car les Text???Value reçoivent la multiplication, mais j'ai un autre champ (TotalValue) que je dois utiliser pour additionner ces 15 champs, il y a des champs qui seront null donc il faut prendre soin de cela également.
    Aussi dans cet exemple si on additionnait tous les champs avec la valeur monétaire, le champ TotalValue serait alors de 371,64 $ ce champ doit être mis à jour à chaque fois qu'un utilisateur clique sur un des boutons des dénominations.

    Quel serait le code?

    Merci
    Claude du Québec, Canada

  4. #4
    Membre extrêmement actif
    Inscrit en
    Avril 2008
    Messages
    2 573
    Détails du profil
    Informations personnelles :
    Âge : 65

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 573
    Par défaut
    bonjour

    Le code exige des props wrappers des unités monetaires.

    Quelque chose comme un total décimal dénommé "MyFortune" qui fait le cumul,ensuite les props citées restitue le montant en unité monetaire approprie.(dollars canadiens et leurs cents ou centièmes).
    Les textboxes servent uniquement à l'user(UI) pour controle de saisie en fait.

    exemple code avec calculatrice:
    - btn0 à btn9 +btnC & TextBox BoxInput
    - 2 TextBoxes BoxEURO100 & BoxEUROCentime pour afficher les montants cumules saisis (billets 100,50 ,20 EURO ET piece CENTIEME,exit des coins & autres quarters)
    - la procédure UpdateTotal() et les props cites s'occupent du reste.

    code behind .vb:

    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
     
    Public Class Form1
     
        Private Sub TextBox3_TextChanged(sender As System.Object, e As System.EventArgs) Handles BoxEUROCentime.TextChanged, BoxEURO100.TextChanged
            Dim txtBox As TextBox = CType(sender, TextBox)
            Dim value As Decimal
            If Decimal.TryParse(txtBox.Text.Trim(), value) Then
                txtBox.Text = value.ToString("c")
                UpdateTotal()
            End If
        End Sub
     
     
        Private Sub btnC_Click(sender As System.Object, e As System.EventArgs) Handles btn2.Click, btnC.Click, btn9.Click, btn8.Click, Btn7.Click, btn6.Click, btn5.Click, btn4.Click, btn3.Click, btn1.Click, btn0.Click
            Dim btn As Button = CType(sender, Button)
            Select Case btn.Name
                Case "btnC"
                    BoxInput.Clear()
                    BoxEURO100.Clear()
                    BoxEUROCentime.Clear()
     
                Case Else
                    BoxInput.Text += btn.Name.Substring(3)
            End Select
     
        End Sub
        Private valueEURO, valueEUROCentime As Decimal
        Private Sub btnCentieme10_Click(sender As System.Object, e As System.EventArgs) Handles btnEURO100.Click, btnEURO50.Click, btnEURO10.Click, btnCentime50.Click, btnCentime20.Click, btnCentime10.Click
            Dim btn As Button = CType(sender, Button)
     
            Select Case btn.Name
                Case "btnEURO100"
                    valueEURO += 100 * ConvertToEuro(BoxInput.Text).ToString()
                Case "btnEURO50"
                    valueEURO += 50 * ConvertToEuro(BoxInput.Text).ToString()
                Case "btnEURO10"
                    valueEURO += 10 * ConvertToEuro(BoxInput.Text).ToString()
                Case "btnCentime50"
                    valueEUROCentime += 50 / 100 * ConvertToEuro(BoxInput.Text).ToString()
                Case "btnCentime20"
                    valueEUROCentime += 20 / 100 * ConvertToEuro(BoxInput.Text).ToString()
                Case "btnCentime10"
                    valueEUROCentime += 10 / 100 * ConvertToEuro(BoxInput.Text).ToString()
     
            End Select
            BoxEURO100.Text = valueEURO.ToString()
            BoxEUROCentime.Text = valueEUROCentime.ToString()
            UpdateTotal()
        End Sub
        Private Function ConvertToEuro(sval As String) As Decimal
            Dim value As Decimal = 0.0
            Try
                If Int32.TryParse(sval, value) Then
                    Return value
                End If
     
            Catch ex As Exception
                'nothing
            End Try
            Return value
        End Function
        Private valueMyFortune As Decimal 'total
        Private Sub UpdateTotal()
            valueMyFortune = valueEURO + valueEUROCentime
            BoxTotal.Text = (EUROS + CENTIEMES).ToString
        End Sub
        'proprietes des unites monetaires
        Public ReadOnly Property EUROS() As Decimal
            Get
                Return [Decimal].Floor(valueMyFortune)
            End Get
        End Property
     
        Public ReadOnly Property CENTIEMES() As Decimal
            Get
                Return [Decimal].Subtract(valueMyFortune, [Decimal].Floor(valueMyFortune))
            End Get
        End Property
     
    End Class
    bon code...

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

Discussions similaires

  1. Les additions invités VirtualBox semblent ne pas être actives
    Par FoX_*D i E* dans le forum VirtualBox
    Réponses: 0
    Dernier message: 26/01/2013, 09h36
  2. Réponses: 0
    Dernier message: 21/04/2010, 10h27
  3. Prob somme SQL (pas trop facile, help!!!!!)
    Par nachi dans le forum Langage SQL
    Réponses: 7
    Dernier message: 20/07/2005, 16h42
  4. utiliser les tag [MFC] [Win32] [.NET] [C++/CLI]
    Par hiko-seijuro dans le forum Visual C++
    Réponses: 8
    Dernier message: 08/06/2005, 15h57
  5. Réponses: 9
    Dernier message: 07/05/2003, 12h57

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