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 :

Erreur : La conversion de la chaine "" en type double n'est pas valide


Sujet :

VB.NET

  1. #1
    Membre du Club
    Femme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Juin 2014
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2014
    Messages : 51
    Points : 40
    Points
    40
    Par défaut Erreur : La conversion de la chaine "" en type double n'est pas valide
    Bonjour , j'ai le même probléme que cette discussion...
    Je fais tout le traitement dans textbox_keydown ,lors de l'exécution dés que j'écris quelque chose dans textbox cette erreur apparait comme exception : La conversion de la chaine "" en type double n'est pas valide
    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
     Private Sub TextBox1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
            If e.KeyCode = Keys.Enter Then
                If TextBox1.Text = "" Then
                    MsgBox("Please Re Enter Your Board Serial Number !")
                    TextBox1.Focus()
                    'leave control and switch to next operations
                    Exit Sub
                End If
            End If
            TextBox1.Text = ""
            Dim SN As String = TextBox1.Text
            Try
                'STEP1: ERROR SOC CHECK
                Dim listFiles_Soc As FileInfo() = Dir1.GetFiles()
                Dim listFiles_EMC As FileInfo() = Dir2.GetFiles()
                Dim file1 As FileInfo
                Dim file2 As FileInfo
     
                Dim fileFound As Boolean = False
                'check if the SN flashed corresponds to the right soc file
                For Each file1 In listFiles_Soc
                    If file1.ToString.Contains(SN) Then
                        'move to the file and open it
                        Dim MyFile As Stream = File.OpenRead(rep1 + "\" + file1.ToString)
                        Dim MyLine As StreamReader = New StreamReader(MyFile, System.Text.Encoding.ASCII)
                        'Read the File Line by Line from the first to the end
                        MyLine.BaseStream.Seek(0, SeekOrigin.Begin)
                        'btest varible indique que l'erreur est non existante au prealable dans chaque ligne 
                        Dim btest As Boolean = False
                        '.peek défini le caractère suivant, si =-1 alors c'est qu'il n'y a plus de caractère et la fin du fichier est donc atteinte
                        While MyLine.Peek() > -1
                            Dim rep As String = MyLine.Peek
                            Dim line As String = MyLine.ReadLine
                            soc_msg.Text = ""
                            'test if the line contains any error soc
                            If line.Contains(SOC_Erreur0) Then
                                btest = True
                                soc_msg.Text = +SOC_Erreur0 + vbNewLine
                                Panel1.BackColor = Color.Red
                            End If
                            'ERROR TYPE2
                            If line.Contains(SOC_Erreur00) Then
                                btest = True
                                soc_msg.Text = +SOC_Erreur00 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur01) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur01 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur02) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur02 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur03) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur03 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur04) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur04 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur05) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur05.ToString + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur06) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur06 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur07) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur07 + vbNewLine
                                Panel1.BackColor = Color.Red
                            End If
                            'ERROR TYPE 3:
                            If line.Contains(SOC_Erreur10) Then
                                btest = True
                                soc_msg.Text = +SOC_Erreur10 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur11) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur11 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur12) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur12 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur13) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur13 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur14) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur14 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur15) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur15 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur16) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur16 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur17) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur17 + vbNewLine
                                Panel1.BackColor = Color.Red
                            End If
     
                            'ERROR TYPE 4:
                            If line.Contains(SOC_Erreur20) Then
                                btest = True
                                soc_msg.Text = +SOC_Erreur20 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur21) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur21 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur22) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur22 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur23) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur23 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur24) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur24 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur25) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur25 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur26) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur26 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur27) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur27 + vbNewLine
                                Panel1.BackColor = Color.Red
                            End If
                            'ERROR TYPE5
                            If line.Contains(SOC_Erreur30) Then
                                btest = True
                                soc_msg.Text = +SOC_Erreur30 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur31) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur31 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur32) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur32 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur33) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur33 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur34) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur34 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur35) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur35 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur36) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur36 + vbNewLine
                                Panel1.BackColor = Color.Red
                            ElseIf line.Contains(SOC_Erreur37) Then
                                btest = True
                                soc_msg.Text += +SOC_Erreur37 + vbNewLine
                                Panel1.BackColor = Color.Red
                            End If
                            If Not btest Then
                                soc_msg.Text = "NO ERRORS FOUND"
                                Panel1.BackColor = Color.Lime
                            End If
                        End While
                        MyLine.Close()
                        MyFile.Close()
                        fileFound = True
                    End If
                    If Not fileFound Then
                        soc_msg.Text = "SOC Log File Not Found"
                        Panel1.BackColor = Color.Orange
                    End If
                Next 'move to the repertory EMC
                'check if the SN flashed corresponds to the right soc file
                For Each file2 In listFiles_EMC
     
                    If file2.ToString.Contains(SN) Then
                        'move to the file and open it
                        Dim MyFile2 As Stream = File.OpenRead(rep2 + "\" + file2.ToString)
                        Dim MyLine2 As StreamReader = New StreamReader(MyFile2, System.Text.Encoding.ASCII)
                        MyLine2.BaseStream.Seek(0, SeekOrigin.Begin)
                        Dim btest As Boolean = False
                        fileFound = True
                        While MyLine2.Peek() > -1
                            Dim rep2 As String = MyLine2.Peek
                            Dim line2 As String = MyLine2.ReadLine
                            soc_msg.Text = ""
                            If line2.Contains(EMC_Erreur) Then
                                btest = True
                                emc_msg.Text = +EMC_Erreur
                                Panel2.BackColor = Color.Red
                            End If
     
                            If Not btest Then
                                emc_msg.Text = "NO ERROR FOUND "
                                Panel2.BackColor = Color.Lime
                            End If
                        End While
                        MyLine2.Close()
                        MyLine2.Close()
                        fileFound = True
                    End If
                Next
                If Not fileFound Then
                    emc_msg.Text = "EMC Log File Not FOUND"
                    Panel2.BackColor = Color.Orange
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub

  2. #2
    Membre actif
    Homme Profil pro
    Developpeur
    Inscrit en
    Février 2013
    Messages
    180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Developpeur

    Informations forums :
    Inscription : Février 2013
    Messages : 180
    Points : 271
    Points
    271
    Par défaut
    si tu pouvais mettre le code d'erreur entier
    ou même si possible délimiter la zone parce que la tu as beaucoup d'endroit différent ou tu modifie des chaines

    et avec ça tu es sur que t'as variable SN sera toujours vide
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
            TextBox1.Text = ""
            Dim SN As String = TextBox1.Text
            Try
                'STEP1: ERROR SOC CHECK
                Dim listFiles_Soc As FileInfo() = Dir1.GetFiles()
                Dim listFiles_EMC As FileInfo() = Dir2.GetFiles()
                Dim file1 As FileInfo
                Dim file2 As FileInfo
     
                Dim fileFound As Boolean = False
                'check if the SN flashed corresponds to the right soc file
                For Each file1 In listFiles_Soc
                    If file1.ToString.Contains(SN) Then

    des petits conseils
    1 donne des vrai nom à tes fonctions ex : TextBox1_KeyDown -> TB_Verifier_KeyDown
    2 les try catch c'est bien mais c'est utile pour nous développeur l'idéale serait que notre code n'est pas besoin de try pour nous remonter les erreurs, aucune erreur
    alors si tu sais que ton code est potentiellement dangereux a un endroit tu met un try pour quelque ligne
    et l’intérêt du try est aussi d'utiliser les finally pour fermer nos variable et fichier
    3 et enfin t'as fonction fait plus de 200 lignes crée des fonction privé pour limiter le code

  3. #3
    Membre du Club
    Femme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Juin 2014
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2014
    Messages : 51
    Points : 40
    Points
    40
    Par défaut
    Merci pour votre conseils , surement ça va m'aider ..concernant les lignes , j'ai voulu faire une certaine Select case pour minimiser le code mais j'ai pas su le faire ici donc je l'ai laissé comme ça ! J'ai essayé de debugger mon code mais j'ai pas pu identifier pourquoi il m'affiche toujours la même erreur si j'ecris une ligne dans un fichier log contenant une erreur parmi ceux postés au début du code

  4. #4
    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 : 42
    Localisation : Belgique

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

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

    Ligne 10 et 11 de votre code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
            TextBox1.Text = ""
            Dim SN As String = TextBox1.Text

    SN sera toujours vide donc tes test sur le SN n'ont pas grand intérêt.

    De plus dans :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    Le .Message ne donne pas l'information de la ligne ayant levée l'erreur, modifié avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
    Sinon +1 avec les remarques de ranzoken

Discussions similaires

  1. [Débutant] Erreur La conversion de la chaîne "" en type 'Double' n'est pas valide.
    Par dragondu83 dans le forum VB.NET
    Réponses: 5
    Dernier message: 24/07/2014, 20h06
  2. [Débutant] La conversion de la chaîne "" en type 'Double' n'est pas valide.
    Par amine_maximus dans le forum VB.NET
    Réponses: 6
    Dernier message: 09/06/2012, 23h11
  3. Réponses: 6
    Dernier message: 04/07/2011, 15h53
  4. Réponses: 12
    Dernier message: 07/02/2011, 23h01
  5. Réponses: 16
    Dernier message: 06/06/2007, 15h46

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