如果同一行中的另一个值等于用户输入的值,我试图存储CSV的一列中的值。截至目前,我只能存储在CSV中找到的值而不是其他列值。有关如何捕获同一行中另一列的任何提示?这是VB.net
Sub CSV()
Dim meternum As Integer
Dim Entermet As String
Entermet = InputBox("Please Enter The Meternum", "Select Start Meter", "", meternum)
Using MyReader As New Microsoft.VisualBasic.
FileIO.TextFieldParser(
"C:\Consumers.csv")
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 Entermet = currentField Then MsgBox(currentField)
Next
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
答案 0 :(得分:1)
ReadFields返回一个字符串数组,所以如果你知道2列的位置,它应该像做
一样简单If currentRow(positionOfColumnToCheck) = Entermet Then
SavedValue = currentRow(positionOfColumnToSave)
End if
但SavedValue会是一个列表。因此,您可能希望使用元组或散列表的列表来保留值和Meternum。