以下は、私のプロジェクトで使用するコードです。
Using Reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(OpenFileDialog1.FileName.ToString())
Reader.TextFieldType = FileIO.FieldType.Delimited
Reader.SetDelimiters("\t")
Dim currentRow As String()
Dim valueArray() As Double = {0, 0, 0, 0}
Dim power3, power2, power1, constVar As Double
power3 = 0.0
power2 = 0.0
power1 = 0.0
constVar = 0.0
While Not Reader.EndOfData
Try
currentRow = Reader.ReadFields()
Dim currentString As String
Dim i As Integer = 0
Dim j As Integer = 0
For Each currentField As String In currentRow
currentString = currentField(0)
MsgBox(currentField)
MsgBox(currentString)
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
私が読んでいるテキストファイルには、次のようにタブで区切られた浮動小数点値が含まれています。
0.5 0.6 0.7 0.8
ただし、現在、コードを実行すると、完全な行が文字列として取得されます"0.5 0.6 0.7 0.8"
各float値の抽出に問題があります。個別に保存できるように、各値を抽出する方法をいくつか提案してください。