I am trying to make a database for creating part numbers and am struggling to access strings in a list of lists. I have a .txt file that I am trying to load information from and into a list of lists. The first line contains the first available project number (in case a new project is added) and gets stored as
newProjNum
. Each line in the file after that is a list that contains information for individual projects as follows (where "first available" takes into account existing part numbers and returns the lowest unused number so that no number is redundant):
PI, Project name, Project number, first available assembly number, first available part number
I have also declared variables in a global file as follows:
Public Property projPartNumInfo As New List(Of String)
Public Property allPartNumInfo As New List(Of List(Of String))
Public Property NewProjNum As Integer
My first check passes and prints out each of the five strings from the
projPartNumInfo
list, concatenated together, through a message box. I can't seem to retrieve those same strings again once I add the
projPartNumInfo
lists into the
allPartNumInfo
list of lists, though. I have tried implementing check 2 in three different ways and can't access the information in
allPartNumInfo
. Version 1 executes the message box command but with 4 new line characters and nothing more--it doesn't see any
item
's in each
line
so it gets nothing from the second for-loop. Versions 2 and 3 throw errors saying that the index is out of range as soon as I try and index into the
allPartNumInfo
list of lists.
Private Sub loadAllPartNumInfo()
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(partNumTextFile)
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
If currentRow.Length = 1 Then
NewProjNum = currentField
Exit Try
Else
projPartNumInfo.Add(currentField)
End If
Next
allPartNumInfo.Add(projPartNumInfo)
projPartNumInfo.Clear()
Catch ex As Microsoft.VisualBasic.
FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
"is not valid and will be skipped.")
End Try
End While
End Using
End Sub
Any suggestions or help? Let me know if anything isn't clear. Thanks in advance for all answers.