我有以下代码,它没有按照我想要的去做。有人可以帮忙吗?这是一个计时器事件项目。该应用程序正在收集值并将其写入.csv文件。
这就是我想要做的:
如果缺少.csv,请创建一个新文件,然后继续添加到该文件中。-->这是可行的
Try
'Check for .csv file
If My.Computer.FileSystem.FileExists(csv_File) = False Then
Else 'if file does not exist, create new file to start writing to it
My.Computer.FileSystem.WriteAllText(csv_File, vbCrLf & Today & "," & Tag_name_Read & "," & itemValues(0).Value.ToString, True)
End If
If My.Computer.FileSystem.FileExists(txt_File) = False Then
FileOpen(1, csv_File, OpenMode.Output)
FileClose(1)
'Check for .txt
If File.Exists(txt_File) = False Then
' Change ".CSV" to the path and filename for the file that
My.Computer.FileSystem.RenameFile(csv_File, txt_File)
End If
End If
Catch ex As Exception
End Try
如果您将来遇到此问题,这是我为解决此问题所做的工作:希望对您有所帮助
Try
'Check for .csv file
If My.Computer.FileSystem.FileExists(csv_File) = False Then
Else
'if file does not exist, create new file to start writing to it
My.Computer.FileSystem.WriteAllText(csv_File, vbCrLf & Today & "," & Tag_name_Read & "," & itemValues(0).Value.ToString, True)
If My.Computer.FileSystem.FileExists(txt_File) = False Then
FileClose()
' Change ".CSV" to the path and filename for the file that you want to rename
My.Computer.FileSystem.RenameFile(csv_File, txt_File)
'File Header
My.Computer.FileSystem.WriteAllText(csv_File, "Date and Time, Tag Name, Value", False)
'Append file
My.Computer.FileSystem.WriteAllText(csv_File, vbCrLf & Today & "," & Tag_name_Read & "," & itemValues(0).Value.ToString, True)
End If
End If
Catch ex As Exception
End Try
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句