Dan2468
Messages postés7Date d'inscriptionlundi 15 juin 2009StatutMembreDernière intervention17 juin 2009
-
15 juin 2009 à 11:43
Mayzz
Messages postés2813Date d'inscriptionmardi 15 avril 2003StatutMembreDernière intervention 2 juin 2020
-
15 juin 2009 à 18:54
Bonjour,
j'aimerais être capable de créer un listbox avec des données contenues dans un fichier csv.
L'adresse complète du fichier csv est stocké dans la variable Dir.
Mais j'obtiens une erreur: NullReferenceException was unhandled, Object reference not an instance of an object.
Comment je peux régler mon problème?????!!
je suis sous visual basic 2008 express... Merci Beaucoup!!!!
Public Class CSVFileReader
Private fileLineArray() As String = Nothing
Public Sub New(ByVal path As String)
Try
fileLineArray = System.IO.File.ReadAllLines(path)
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Sub
Public Function GetContentArray() As String()()
Dim fileContentArray(fileLineArray.Length - 1)() As String
Try
Dim i As Integer = 0
For i = 0 To fileLineArray.Length - 1
Dim line As String = fileLineArray(i)
fileContentArray(i) = line.Split(",")
Next
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
Dan2468
Messages postés7Date d'inscriptionlundi 15 juin 2009StatutMembreDernière intervention17 juin 2009 15 juin 2009 à 11:47
Public Class CSVFileReader
Private fileLineArray() As String = Nothing
Public Sub New(ByVal path As String)
Try
fileLineArray = System.IO.File.ReadAllLines(path)
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
End Sub
Public Function GetContentArray() As String()()
Dim fileContentArray(fileLineArray.Length - 1)() As String
Try
Dim i As Integer = 0
For i = 0 To fileLineArray.Length - 1
Dim line As String = fileLineArray(i)
fileContentArray(i) = line.Split(",")
Next
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
Mayzz
Messages postés2813Date d'inscriptionmardi 15 avril 2003StatutMembreDernière intervention 2 juin 202028 15 juin 2009 à 18:54
Salut,
Travaille avec les listes en .Net, c'est plus simple.
Public Function GetContentArray(ByVal Path As String) As List(Of String)
'
Dim fileContentArray As New List(Of String)
'
Try
'
fileLineArray = System.IO.File.ReadAllLines(Path)
'
Dim i As Integer = 0
'
For i = 0 To fileLineArray.Length - 1
'
Dim line As String = fileLineArray(i)
fileContentArray.AddRange(line.Split(",").ToList())
'
Next
'
Catch ex As Exception
'
Throw New Exception("erreur de lecture du fichier CSV, celui-ci est peut-tre corrompu")
'
End Try
'
Return fileContentArray
'
End Function
++
Si le déboguage est l'art d'enlever les bogues, la programmation doit être l'art de les créer. <