I am having some problems to determine how can i remove the errors i am having using FileHelpers with the option strict on.
I initialized the class MasterDetails
Private _res As MasterDetails()
The function to call the MasterDetailEngine
Private Function ReadCsvFile(ByVal fileName As String, ByVal tipodoc As String) As Boolean
engine = New MasterDetailEngine(GetType(CabecDocVgr), GetType(LinhasDocVgr), CommonSelector.MasterIfContains,
"@")
_res = engine.ReadFile(strStartPath)
Return true
End Function
This is the class for the Master:
<DelimitedRecord(";")>
Public NotInheritable Class CabecDocVgr
Public TipoLinha As String
Public Doc As String
Public Entidade As String
Public DataDoc As String
Public RefDoc As String
End Class
This one, for the Details:
<DelimitedRecord(";")> _
Public NotInheritable Class LinhasDocVgr
Public Tipolinha As String
Public Artigo As String
Public Armazem As String
Public Localizacao As String
Public Lote As String
Public Qtd As Integer
Public UniMedida As String
Public DataValidade As String
End Class
Each master/detail is to create a new document with a header and the related rows.
I can give one example where the error appears, when i call a member of the Master or Details class:
Private Function TransformaDocF(ByVal tipoDoc As String) As Boolean
For numdoc As Integer = 0 To _res.Length - 1
Dim documentosOrigem(0) As Object
Dim docOrigem As New GcpBEDocumentoCompra
Dim docDestino As New GcpBEDocumentoCompra
Dim query As String = String.Format("SELECT TOP 1 NumDoc FROM cabecdoc WHERE RefDocOrig='{0}'",
_res(numdoc).Master.doc)
Dim lista As New StdBELista()
lista = Motor.Consulta(query)
If Not lista.Vazia Then
If Not lista.NoInicio And Not lista.NoFim Then
Dim numeroDoc As Integer = CInt(lista.Valor("NumDoc"))
'bExecuta = True
End If
End If
docOrigem = Motor.Comercial.Compras.Edita("000", "VGR", "2013", _res(numdoc).Master.doc)
documentosOrigem(0) = docOrigem
docDestino.TipoEntidade = "F"
docDestino.Serie = "2013"
docDestino.Entidade = docOrigem.Entidade.TrimStart(CChar("0"))
'DocDestino.DataDoc = "01-01-2013"
docDestino.Tipodoc = "VFA"
docDestino.RefDocOrig = _res(numdoc).Master.refDoc
Try
If docOrigem.Linhas.NumItens > 0 Then
For numlinha As Integer = 0 To _res(numdoc).Details.Length - 1
If docOrigem.Linhas(numlinha + 1).Artigo = _res(numdoc).Details(numlinha).Artigo Then
docOrigem.Linhas(numlinha + 1).Quantidade = docOrigem.Linhas(numlinha + 1).QuantSatisfeita +
_res(numdoc).Details(numlinha).Qtd
End If
Next
End If
Motor.Comercial.Vendas.TransformaDocumentoEX2(documentosOrigem, CType(docDestino, GcpBEDocumentoVenda), True)
Return True
Catch ex As Exception
MessageBox.Show(ex.Message)
Return False
End Try
Next
Return True
End Function
For example, calling _res(numdoc).Master.refDoc
gives me the error: " Option Strict On disallows late binding"
Any ideas about what i need to modify so the error can be gone?
Thank you
Try using generics. I'm not very good at VB.NET but I think it should look something like this:
'declare _res as an array of MasterDetails<CabecDocVgr, LinhasDocVgr>
Dim _res As MasterDetails(Of CabecDocVgr, LinhasDocVgr)()
'instantiate the generic version of the FileHelpers engine
Dim engine = New MasterDetailEngine(Of CabecDocVgr, LinhasDocVgr)(CommonSelector.MasterIfContains, "@")
'should not cause 'late binding error' since the results are strongly typed
_res = engine.ReadFile("")