I am trying to split a string and take the split parts and assign them to variables. This works fine with the first variable but I cannot get the second variable to work.
For Each columnQuarter As DataColumn In dt.Columns
Dim s As String = columnQuarter.ColumnName
Dim words As String() = s.Split("-")
Dim Year As String = words(0)
Dim Quarter As String = words(1)
Debug.WriteLine(Year)
Debug.WriteLine(Quarter)
At line "Dim Quarter As String = words(1)" I get error code "IndexOutofRangeException was unhandled. Index was outside the bounds of the array."
An example of a ColumnName would be 2012-Q1.
ADDITIONAL INFORMATION:
Here is the code that I use to add my columns to my dataTable. As you can see my first two columns do not contain "-".
tickerColumn = New DataColumn("Ticker", Type.GetType("System.String"))
consistencyColumn = New DataColumn("Consistency", Type.GetType("System.Int32"))
dt.Columns.Add(tickerColumn)
dt.Columns.Add(consistencyColumn)
With Me
lr = Now.Year - 1901
For i = 1 To lr
column = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = Now.Year - i & "-Q4"
dt.Columns.Add(column)
column = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = Now.Year - i & "-Q3"
dt.Columns.Add(column)
column = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = Now.Year - i & "-Q2"
dt.Columns.Add(column)
column = New DataColumn
column.DataType = System.Type.GetType("System.Int32")
column.ColumnName = Now.Year - i & "-Q1"
dt.Columns.Add(column)
Next i
End With