我有升级旧版vb应用程序(使用文件助手)的艰巨任务,但出于某种原因,它似乎忽略了我将其标记为定界记录这一事实。
在表单中,它使用以下命令将csv文件附加到与c#的行为类似的记录。
Private Sub browseButton_Click(sender As System.Object, e As System.EventArgs) _
Handles browseButton.Click
Try
Dim file = GetFile()
'' Errors
Dim errors As New Dictionary(Of Integer, String)
If IO.File.Exists(file) Then
Dim engine As New FileHelperEngine(Of AveryOrderCsv)
_records = CType(engine.ReadFile(file), AveryOrderCsv()).ToList()
Dim count As Integer = 0
Dim success As Integer = 0
For Each averyOrderCsv As AveryOrderCsv In _records
Try
ImportProgressBar.Value = count
ImportProgressLabel.Text = String.Format("Importing {0} of {1} dockets",
count + 1, _records.Count())
System.Windows.Forms.Application.DoEvents()
If CreateSop(averyOrderCsv) Then
success = success + 1
End If
Catch ex As Exception
errors.Add(count, ex.Message)
End Try
count = count + 1
Next
End If
Catch ex As Exception
ExceptionManager.HandleUnexpectedException(ex)
End Try
班级
Imports AveryIntegration.Common.CSV
Imports FileHelpers
Imports System
Imports System.Diagnostics
Namespace AveryIntegration.Common.CSV.Records
<DelimitedRecord(",")>
Public Class AveryOrderCsv
<FieldConverter(GetType(CustomStringConvertor))>
<FieldQuoted>
Public String2 As String
<FieldConverter(GetType(CustomStringConvertor))>
<FieldQuoted>
Public String3 As String
<FieldConverter(GetType(CustomStringConvertor))>
<FieldQuoted>
Public String4 As String
<FieldConverter(GetType(CustomStringConvertor))>
<FieldQuoted>
Public String5 As String
<FieldConverter(GetType(CustomStringConvertor))>
<FieldQuoted>
Public String10 As String
<FieldConverter(GetType(CustomStringConvertor))>
<FieldQuoted>
Public String15 As String
Public Decimal1 As Decimal
Public Decimal5 As Decimal
Public Decimal8 As Decimal
Public Decimal9 As Decimal
Public Decimal10 As Decimal
Public Date1 As DateTime
Public Ticket2 As Integer
<DebuggerNonUserCode>
Public Sub New()
MyBase.New()
End Sub
End Class
End Namespace
以下是我遇到的错误,但是从上面可以看到,我已将其声明为定界记录并导入了导入FileHelpers
答案 0 :(得分:1)
在VB中,该属性必须在同一逻辑行上。
<DelimitedRecord(",")> Public Class AveryOrderCsv
或
<DelimitedRecord(",")> _
Public Class AveryOrderCsv
属性相同。
在Visual Basic中,该属性用尖括号括起来,并且必须在同一逻辑行上;如果需要换行,可以使用换行符。