I have the following snippit of code.

Dim intMax As Integer = 5
Dim OriginalString As String = txtRecord.Text
Dim OriginalArray As String() = Strings.Split(OriginalString, ",")

Dim FinalArrayGeneric As New List(Of String)
Dim FinalArray As String()



For intCount As Integer = 0 To UBound(OriginalArray)
If intCount <= intMax Then
FinalArrayGeneric.Add(OriginalArray(intCount))
End If
Next



FinalArray = FinalArrayGeneric.ToArray()

If IsNothing(FinalArray(5)) Then
FinalArray(5) = " "

End If

txtField1.Text = FinalArray(0).ToString()
txtField2.Text = FinalArray(1).ToString()
txtField3.Text = FinalArray(2).ToString()
txtField4.Text = FinalArray(3).ToString()
txtField5.Text = FinalArray(4).ToString()
txtField6.Text = FinalArray(5).ToString()



This is a class project and it does basically what I need it to do. Here is a quick breakdown.

There is a textbox area for someone to enter a sentence that turns to an array and they want us to break it out by commas up to 6 fields. Anything over 6 fields I need to just drop which this seems to do. My issue seems to be when I dont have enough commas (indexes for the text boxes).

In my mind I thought this would work

If IsNothing(FinalArray(5)) Then
FinalArray(5) = " "

but unfortunatly it doesnt. Also I wanted to do it more programatically than listing out all 6 boxes incase more would be added.


This is a test sentence

Record #10, John E. Doe, 123 Main Street, Columbus, Ohio 43232

Currently it breaks everything out but since the FinalArray(5) is null I get an error.