index out of range exception
-
im running this function to convert a list of code into a certain standard.. the problem is, when i choose the files (where i get the value of coop) and directory (where i compare coop with the list in the directory) this msg come out "index out of range exception". But if i choose local file and directory example file from my desktop and my d:/ there's np error.. but if i choose the file from other map drive the error happen at the Catch part.
Private Sub SEMAK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SEMAK.Click
Dim fileName As String = TextBox1.Text.Trim Dim lineNumber As Integer = 0 Dim sr As StreamReader = New StreamReader(fileName) Dim conn As New SqlClient.SqlConnection("Data Source=10.0.0.70;User ID= sysadm;Password=sysadm;Initial Catalog=SPGA\_Latihan;Persist Security Info=True;") Dim tarikh As String = "" Dim runNo As String = "" Dim coop As String = "" Dim line As String = "" Do line = sr.ReadLine() If line <> Nothing Then Try tarikh = line.Substring(0, 8).Trim() runNo = line.Substring(9, 5).Trim() coop = line.Substring(15).Trim() Catch ex As Exception Console.Write(ex.ToString()) End Try Dim strSQL As String = "INSERT INTO portal (tarikh,runNo, coop) VALUES (@tarikh, @runNo, @coop)" Dim cmd As New System.Data.SqlClient.SqlCommand(strSQL, conn) conn.Open() cmd.Parameters.Add(New SqlClient.SqlParameter("@tarikh", SqlDbType.Char, 8)) cmd.Parameters("@tarikh").Value = tarikh cmd.Parameters.Add(New SqlClient.SqlParameter("@runNo", SqlDbType.Char, 20)) cmd.Parameters("@runNo").Value = runNo cmd.Parameters.Add(New SqlClient.SqlParameter("@coop", SqlDbType.VarChar, 100)) cmd.Parameters("@coop").Value = coop cmd.ExecuteNonQuery() conn.Close() Dim dirB1 As DirectoryInfo = New DirectoryInfo(TextBox2.Text) Try convertCoop(coop) Dim dA1 As DirectoryInfo Dim dirB2 As FileSystemInfo() = dirB1.GetDirectories Dim strSQL2 As String = "SELECT folder, portal FROM kodPortal"
-
im running this function to convert a list of code into a certain standard.. the problem is, when i choose the files (where i get the value of coop) and directory (where i compare coop with the list in the directory) this msg come out "index out of range exception". But if i choose local file and directory example file from my desktop and my d:/ there's np error.. but if i choose the file from other map drive the error happen at the Catch part.
Private Sub SEMAK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SEMAK.Click
Dim fileName As String = TextBox1.Text.Trim Dim lineNumber As Integer = 0 Dim sr As StreamReader = New StreamReader(fileName) Dim conn As New SqlClient.SqlConnection("Data Source=10.0.0.70;User ID= sysadm;Password=sysadm;Initial Catalog=SPGA\_Latihan;Persist Security Info=True;") Dim tarikh As String = "" Dim runNo As String = "" Dim coop As String = "" Dim line As String = "" Do line = sr.ReadLine() If line <> Nothing Then Try tarikh = line.Substring(0, 8).Trim() runNo = line.Substring(9, 5).Trim() coop = line.Substring(15).Trim() Catch ex As Exception Console.Write(ex.ToString()) End Try Dim strSQL As String = "INSERT INTO portal (tarikh,runNo, coop) VALUES (@tarikh, @runNo, @coop)" Dim cmd As New System.Data.SqlClient.SqlCommand(strSQL, conn) conn.Open() cmd.Parameters.Add(New SqlClient.SqlParameter("@tarikh", SqlDbType.Char, 8)) cmd.Parameters("@tarikh").Value = tarikh cmd.Parameters.Add(New SqlClient.SqlParameter("@runNo", SqlDbType.Char, 20)) cmd.Parameters("@runNo").Value = runNo cmd.Parameters.Add(New SqlClient.SqlParameter("@coop", SqlDbType.VarChar, 100)) cmd.Parameters("@coop").Value = coop cmd.ExecuteNonQuery() conn.Close() Dim dirB1 As DirectoryInfo = New DirectoryInfo(TextBox2.Text) Try convertCoop(coop) Dim dA1 As DirectoryInfo Dim dirB2 As FileSystemInfo() = dirB1.GetDirectories Dim strSQL2 As String = "SELECT folder, portal FROM kodPortal"
Have you bothered to walk through the code in te debugger ? I assume this means you're not getting any data back from your database.
Christian Graus Driven to the arms of OSX by Vista.
-
im running this function to convert a list of code into a certain standard.. the problem is, when i choose the files (where i get the value of coop) and directory (where i compare coop with the list in the directory) this msg come out "index out of range exception". But if i choose local file and directory example file from my desktop and my d:/ there's np error.. but if i choose the file from other map drive the error happen at the Catch part.
Private Sub SEMAK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SEMAK.Click
Dim fileName As String = TextBox1.Text.Trim Dim lineNumber As Integer = 0 Dim sr As StreamReader = New StreamReader(fileName) Dim conn As New SqlClient.SqlConnection("Data Source=10.0.0.70;User ID= sysadm;Password=sysadm;Initial Catalog=SPGA\_Latihan;Persist Security Info=True;") Dim tarikh As String = "" Dim runNo As String = "" Dim coop As String = "" Dim line As String = "" Do line = sr.ReadLine() If line <> Nothing Then Try tarikh = line.Substring(0, 8).Trim() runNo = line.Substring(9, 5).Trim() coop = line.Substring(15).Trim() Catch ex As Exception Console.Write(ex.ToString()) End Try Dim strSQL As String = "INSERT INTO portal (tarikh,runNo, coop) VALUES (@tarikh, @runNo, @coop)" Dim cmd As New System.Data.SqlClient.SqlCommand(strSQL, conn) conn.Open() cmd.Parameters.Add(New SqlClient.SqlParameter("@tarikh", SqlDbType.Char, 8)) cmd.Parameters("@tarikh").Value = tarikh cmd.Parameters.Add(New SqlClient.SqlParameter("@runNo", SqlDbType.Char, 20)) cmd.Parameters("@runNo").Value = runNo cmd.Parameters.Add(New SqlClient.SqlParameter("@coop", SqlDbType.VarChar, 100)) cmd.Parameters("@coop").Value = coop cmd.ExecuteNonQuery() conn.Close() Dim dirB1 As DirectoryInfo = New DirectoryInfo(TextBox2.Text) Try convertCoop(coop) Dim dA1 As DirectoryInfo Dim dirB2 As FileSystemInfo() = dirB1.GetDirectories Dim strSQL2 As String = "SELECT folder, portal FROM kodPortal"
Have you remembered that the index for substring starts at 0, therefore SubString(15) would return the string from the 16th character of the string.
Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
-
Have you bothered to walk through the code in te debugger ? I assume this means you're not getting any data back from your database.
Christian Graus Driven to the arms of OSX by Vista.
i am using the debugger.. the thing is, i can read data from the files but when it comes to this part in convertCoop, i cannot get value from "portal" but the value of "coop" is ok. after this part, at the Catch part, the msg "index out of range exception" come out. is it bcoz the directory that i choose got a lot (thounsands) of folder n files? bcoz when i choose directory that only have a few folders n files, it runs smoothly.. no errors, and i can see all the missing files in that directory.
portal = ds.Tables(0).Rows(0).Item("portal")
-
Have you remembered that the index for substring starts at 0, therefore SubString(15) would return the string from the 16th character of the string.
Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
i dont have any problems with my substring.. i can read data from file using that code.. as u can see my reply at Christian answers, the problem start if i choose directory that have thousands of folder n files. but if a choose a directory that have just a few folder n files.. it can run and can get output from the prgm..