Splitting a string into an array

First the code:
Dim upd As String
While (ssreadline.Peek() > -1)
errorhandler:
upd = ssreadline.ReadLine()

Dim i As String = upd
Dim a() As String
Dim j As Integer
a = Split(i, ",,")
For j = 0 To a.GetUpperBound(0)
Debug.WriteLine("a0 =" + a(0))
Debug.WriteLine("a1 =" + a(1))
Debug.WriteLine("a2 =" + a(2))
a(j) = LTrim(RTrim(a(j)))
j = j + 1
a(j) = LTrim(RTrim(a(j)))
j = j + 1
a(j) = LTrim(RTrim(a(j)))
Next
Dim test As Decimal
test = CDec(a(2))
m_sConnection = "Driver=Microsoft Visual Foxpro Driver;UID=;SourceType=DBF;SourceDB=c:inetpubwwwrootsalesdb"
m_cnConnection = New ADODB.Connection()
m_cnConnection.Open(m_sConnection)
rs = New ADODB.Recordset()
daTitles = New OleDbDataAdapter()
SQLText = "Select * from upsalesdb.dbf Where pnum = '" & a(0).ToString & "'"
rs.Open(SQLText, m_cnConnection)
If rs.EOF Then
SQLText = "INSERT into upsalesdb.dbf(pnum, descript, price)VALUES('" & a(0).ToString & "', '" & a(1) & "'," & test & ")"
Else
SQLText = "update upsalesdb.dbf set pnum = '" & a(0).ToString & "', descript = '" & a(1).ToString & "', price = " & test & " where pnum = '" & a(0).ToString & "'"
End If
rs.Close()
rs.Open(SQLText, m_cnConnection)
rs = Nothing
m_cnConnection.Close()
m_cnConnection = Nothing
File.Copy("c:\inetpub\wwwroot\salesdb\upsalesdb.dbf", "c:\inetpub\wwwroot\salesdb\salesdb.dbf", True)
End While

This works on win xp however when I moved it over to windows 2k machine when I try to do anything with a(1) or a(2) I get an error that index outside of bounds of array. When I look in the debugger I see the values of a(0) a(1) and a(2) but it errors when it tries to write to the debugger. its almost as if it goes through once and then one the second time the string doesn't exit. Any suggestions please email me jclark84@hotmail.com
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories