【发布时间】:2021-05-13 05:00:25
【问题描述】:
我遇到了一个基本问题。我想要的是通过 CSV 进行解析,以便比较一些字符串,如果找到的话,写在下面。
确切地说,我有一个程序,我可以在其中拖放一些按钮,当我放下这个按钮时,我想将它的新位置保存在相应列下方的第一个空单元格上。 这是我的 CSV 示例:
所以我从我的 CSV 中对 .x/.y 进行子串化,并在 textFieldParser 的帮助下将下拉按钮中的名称与每个单元格进行比较。当它找到一个相等的表达式时,我的循环似乎停止工作了。
但这是我不知道该怎么说的问题,我的程序写在它下面。我能弄清楚的第一个原因是因为我的解析器一直运行到 endOfData 并且我希望它一直运行到 endOfDat + 一行。 第二个是因为我不知道是否可以在 textFieldParser 中使用 fieldwriter,我的意思是我尝试使用 row+1 创建一个变量并写在下面,但是当我使用 fileWriter 时没有任何反应。
现在是我的代码示例:
Private Sub manageCsv(ByVal sender As Button)
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("..\..\Pic\csvPic.csv")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim rowPlusOne As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
rowPlusUn = MyReader.ReadFields()
Dim currentField As String
Dim str As String = btnSender.Name.Substring(3)
Dim nameDelimited As String
Dim x As Integer
For Each currentField In currentRow
''Search the corresponding field''
x = InStr(currentField, ".")
If Not (currentField.Equals("imagefile")) Then ''imagefile is the first index of my csv''
nameDelimited = currentField.Substring(0, x) ''substr the extension''
If nameDelimited.Equals(str) Then
writeCsv("..\..\Image\csvPic.csv", nameDelimited, ",")
''Ofc the "+1" does not work but that was the idea''
currentRow(+1) = lblImgName.Text
currentRow(+1) = btnSender.Location.ToString
Exit For
End If
End If
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
我希望它足够清楚,如果不是,我会尝试详细说明。感谢您的帮助
【问题讨论】:
-
为什么是 csv 文件?有更简单的方法可以做到这一点。
-
这是我老师的指示,我不知道他为什么要那样精确....但是很痛苦。
-
列标题是按钮 .Name(或 .Text)加上 X 和 Y 坐标吗?目的是在表单关闭后重新创建位置吗?
-
是的,就是这样。是的,它应该是一个迷你 faceApp,所以我们从几个 img 保存和加载位置