Ajouter un commentaire

martin27
Message d'erreur dans une application vb.net

Bonjour tout le monde,
j'ai un message d'erreur concernant l'instanciation d'un objet:

System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet. à PoMailPh.frmPrinc.procVerifFichier() à PoMailPh.frmPrinc.fct_watch_folder()

Suite a des recherches, j'ai su que ca se regle par new mais je vois pas ou je peux l'integrer et de quel objet il s'agit dans cette partie de code.

Private Sub procVerifFichier()
        Dim i As Integer
        Dim sFiles() As String
        Dim FreeF As Integer
        Dim str() As String
        Dim tmp() As String
 
 
 
        Do
            Try
                'System.Threading.Thread.Sleep(5000)
                If Not File.Exists(f_in & "\pomail.lock") Then
                    'pour avoir les noms des fichiers et des sous-répertoires
                    sFiles = Directory.GetFiles(f_in)
                    For i = 0 To sFiles.GetUpperBound(0)
 
                        If InStr(sFiles(i), ".txt") > 0 Then
 
                            'System.Threading.Thread.Sleep(5000)
                            FreeF = FreeFile()                                            'Possibilité de mettre 1************
                            FileOpen(FreeF, sFiles(i), OpenMode.Input)                   'Ouverture du fichier créé**********
                            str = Split(InputString(FreeF, FileLen(sFiles(i))), Chr(10)) 'Séparation des lignes du fichier***
                            FileClose(FreeF)
                            File.Delete(archive & sFiles(i).Substring(27, sFiles(i).Length - 27))
                            File.Move(sFiles(i), archive & sFiles(i).Substring(27, sFiles(i).Length - 27))
                            'MsgBox(sFiles(i), archive & sFiles(i))
 
                            With txtwatch
 
                                .SelectionStart = Len(txtwatch.Text)
                                .SelectionProtected = False
                                .SelectionStart = Len(txtwatch.Text) + 1
                                .SelectionColor = System.Drawing.Color.Red
                                .SelectedText = "Fichier créé : " & Replace(sFiles(i), f_in, "") & " " & Date.Now & vbCrLf
                                .SelectionProtected = True
                                .Focus()
                                .SelectionStart = txtwatch.Text.Length
                                .ScrollToCaret()
                            End With
                            tmp = Split(Replace(Replace(str(0), Chr(34), ""), "'", " "), ";")
                            'If tmp(2).ToUpper <> "V" Then
                            'Exit Sub
                            'end if
                            If tmp(2).ToUpper = "V" Then
                                fct_fill_sql(str, sFiles(i).Substring(27, 2).ToUpper)
                                fct_fill_excel(str, sFiles(i).Substring(27, 2).ToUpper)
                            End If
                        End If
                        If File.Exists(f_in & "\pomail.lock") Then Exit For
                    Next
                End If
 
            Catch ex As Exception
                fct_send_mail(envoyeur, warning, "ERREUR PO VIA MAIL " & Replace(sFiles(i), f_in, ""), 0, ex.ToString, "none")
                '# erreur no 1
                fct_exec_sql("UPDATE pur_order SET err=1 WHERE pur_order.po_number='0'")
 
            End Try
            Exit Do
        Loop
    End Sub
 

dans .fct_watch_folder(), j'appelle la fonction procVerifFichier().
Merci beaucoup pour votre aide.

Filtered HTML

Plain text

CAPTCHA
Cette question permet de vérifier que vous n'êtes pas un robot spammeur :-)
 X   X  N   N  V     V   SSS   Y   Y 
X X NN N V V S Y Y
X N N N V V SSS Y
X X N NN V V S Y
X X N N V SSSS Y