help help help
-
Hello everyone, I'm working on an application using VB.Net and Access. The program will read a text file similar to this --> IM,CRP-FURT-0044148,D,0,@PROD02;IMAGES\00\00;CRP-FURT-0044148.TIF;2 IM,CRP-FURT-0044149, ,0,@PROD02;IMAGES\00\00;CRP-FURT-0044149.TIF;2 IM,CRP-FURT-0044150, ,0,@PROD02;IMAGES\00\00;CRP-FURT-0044150.TIF;2 IM,CRP-FURT-0044151, ,0,@PROD02;IMAGES\00\00;CRP-FURT-0044151.TIF;2 .. and save it to access database, but I keep getting [ array out of bound error ] & [ object reference not set to an instance of an object ] code for when click import: conv1.ShowDialog() If (Not conv1.convFilePath Is Nothing) Then Me.theDbConnection = db1.createNewDb flag1 = db1.importData(Me.theDbConnection, conv1.convFilePath) End If If flag1 Then Try Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection) Me.dataGridImgs.DataSource = table1 Me.currentRec.Text = ("1\" & table1.Rows.Count) << objct reference not set error Catch obj As ObjectDisposedException MessageBox.Show(obj.Message) End Try End If ---------- Function for the text delimiter file Private Function cnvtIpro(ByVal cnvtFile As String, ByVal outFile As String) As Boolean Dim flag1 As Boolean = True Try Dim reader1 As New StreamReader(cnvtFile) Dim writer1 As New StreamWriter(outFile) Dim textArray3 As String() = reader1.ReadToEnd.Split(New Char() {ChrW(10)}) Dim num1 As Integer = textArray3.Length reader1.Close() Dim num2 As Integer = 0 Do While (num2 < num1) Try Dim textArray1 As String() = textArray3(num2).Trim.Split(New Char() {","c}) If (textArray1.Length > 1) And (textArray1(0).ToUpper Is "IM") Then Dim textArray2 As String() = textArray1(4).Split(New Char() {";"c}) Dim text1 As String = Me.setOutLine(textArray1(1), Path.GetDirectoryName(cnvtFile), (textArray2(1) & "\" & textArray2(2)), textArray1(2), textArray2(0).TrimStart(New Char() {"@"c}), "0") writer1.WriteLine(text1) End If Catch exception1 As Exception Dim result1 As DialogResult = MessageBox.Show((textArray3(num2) & " :INVALID"), exception1.Message, MessageBoxButtons.OKCancel, MessageBoxIc
-
Hello everyone, I'm working on an application using VB.Net and Access. The program will read a text file similar to this --> IM,CRP-FURT-0044148,D,0,@PROD02;IMAGES\00\00;CRP-FURT-0044148.TIF;2 IM,CRP-FURT-0044149, ,0,@PROD02;IMAGES\00\00;CRP-FURT-0044149.TIF;2 IM,CRP-FURT-0044150, ,0,@PROD02;IMAGES\00\00;CRP-FURT-0044150.TIF;2 IM,CRP-FURT-0044151, ,0,@PROD02;IMAGES\00\00;CRP-FURT-0044151.TIF;2 .. and save it to access database, but I keep getting [ array out of bound error ] & [ object reference not set to an instance of an object ] code for when click import: conv1.ShowDialog() If (Not conv1.convFilePath Is Nothing) Then Me.theDbConnection = db1.createNewDb flag1 = db1.importData(Me.theDbConnection, conv1.convFilePath) End If If flag1 Then Try Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection) Me.dataGridImgs.DataSource = table1 Me.currentRec.Text = ("1\" & table1.Rows.Count) << objct reference not set error Catch obj As ObjectDisposedException MessageBox.Show(obj.Message) End Try End If ---------- Function for the text delimiter file Private Function cnvtIpro(ByVal cnvtFile As String, ByVal outFile As String) As Boolean Dim flag1 As Boolean = True Try Dim reader1 As New StreamReader(cnvtFile) Dim writer1 As New StreamWriter(outFile) Dim textArray3 As String() = reader1.ReadToEnd.Split(New Char() {ChrW(10)}) Dim num1 As Integer = textArray3.Length reader1.Close() Dim num2 As Integer = 0 Do While (num2 < num1) Try Dim textArray1 As String() = textArray3(num2).Trim.Split(New Char() {","c}) If (textArray1.Length > 1) And (textArray1(0).ToUpper Is "IM") Then Dim textArray2 As String() = textArray1(4).Split(New Char() {";"c}) Dim text1 As String = Me.setOutLine(textArray1(1), Path.GetDirectoryName(cnvtFile), (textArray2(1) & "\" & textArray2(2)), textArray1(2), textArray2(0).TrimStart(New Char() {"@"c}), "0") writer1.WriteLine(text1) End If Catch exception1 As Exception Dim result1 As DialogResult = MessageBox.Show((textArray3(num2) & " :INVALID"), exception1.Message, MessageBoxButtons.OKCancel, MessageBoxIc
First, I'm not reading through all this junk trying to find out where the error is. Point out on which line the errors occur and keep the code snippets to a relative minimum. You've posted WAY too much. The error "object reference not set to an instance of an object" is cuased because your trying to use an object that doesn't exist. For example, in your first code snippet, your code is making a couple of very bad assumptions.
Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection)
Me.dataGridImgs.DataSource = table1
Me.currentRec.Text = ("1\" & table1.Rows.Count)When you call
imgs1.fillDataTable(Me.theDbConnection)
, did it actually return anything?? If not, thentable1
doesn't refer to table, hence you can't call any methods on it, which your doing 2 lines later. Second, in theMe.currentRec.Text...
line, even iftable1
points to an actual table object, does it contain any Rows? Probably not. Check the status of your objects before you try and use them. Maybe something like this:Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection)
If Not table1 Is Nothing Then
Me.dataGridImgs.DataSource = table1
If table1.Rows.Count > 0 Then
Me.currentRec.Text = ("1\" & table1.Rows.Count)
End If
End IfThe error "Array out of bounds" means that you're trying to get at more objects in an array than are actually contained in the array. For example, if there are 10 objects in an array, they're indexed as 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. You're trying to get at index number 10 when it doesn't exist.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
First, I'm not reading through all this junk trying to find out where the error is. Point out on which line the errors occur and keep the code snippets to a relative minimum. You've posted WAY too much. The error "object reference not set to an instance of an object" is cuased because your trying to use an object that doesn't exist. For example, in your first code snippet, your code is making a couple of very bad assumptions.
Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection)
Me.dataGridImgs.DataSource = table1
Me.currentRec.Text = ("1\" & table1.Rows.Count)When you call
imgs1.fillDataTable(Me.theDbConnection)
, did it actually return anything?? If not, thentable1
doesn't refer to table, hence you can't call any methods on it, which your doing 2 lines later. Second, in theMe.currentRec.Text...
line, even iftable1
points to an actual table object, does it contain any Rows? Probably not. Check the status of your objects before you try and use them. Maybe something like this:Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection)
If Not table1 Is Nothing Then
Me.dataGridImgs.DataSource = table1
If table1.Rows.Count > 0 Then
Me.currentRec.Text = ("1\" & table1.Rows.Count)
End If
End IfThe error "Array out of bounds" means that you're trying to get at more objects in an array than are actually contained in the array. For example, if there are 10 objects in an array, they're indexed as 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. You're trying to get at index number 10 when it doesn't exist.
Dave Kreskowiak Microsoft MVP - Visual Basic
Dave Kreskowiak wrote:
You've posted WAY too much.
Yep, that is why I read it only a quarter of a way through, and then went to different forum :rolleyes:
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
-
First, I'm not reading through all this junk trying to find out where the error is. Point out on which line the errors occur and keep the code snippets to a relative minimum. You've posted WAY too much. The error "object reference not set to an instance of an object" is cuased because your trying to use an object that doesn't exist. For example, in your first code snippet, your code is making a couple of very bad assumptions.
Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection)
Me.dataGridImgs.DataSource = table1
Me.currentRec.Text = ("1\" & table1.Rows.Count)When you call
imgs1.fillDataTable(Me.theDbConnection)
, did it actually return anything?? If not, thentable1
doesn't refer to table, hence you can't call any methods on it, which your doing 2 lines later. Second, in theMe.currentRec.Text...
line, even iftable1
points to an actual table object, does it contain any Rows? Probably not. Check the status of your objects before you try and use them. Maybe something like this:Dim table1 As DataTable = imgs1.fillDataTable(Me.theDbConnection)
If Not table1 Is Nothing Then
Me.dataGridImgs.DataSource = table1
If table1.Rows.Count > 0 Then
Me.currentRec.Text = ("1\" & table1.Rows.Count)
End If
End IfThe error "Array out of bounds" means that you're trying to get at more objects in an array than are actually contained in the array. For example, if there are 10 objects in an array, they're indexed as 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. You're trying to get at index number 10 when it doesn't exist.
Dave Kreskowiak Microsoft MVP - Visual Basic