tá aqui o código para converter de BCD para texto, se alguem precisar.
Dim HighDigit, LowDigit As Char
Dim BCDbyte(87000) As Byte
Dim x As Integer
Dim r As Integer = 0
Dim ArtType, Price, ArtName, ProdGroup, TaxClass, DiscAmou, DiscPerc, EAN13 As String
If ofdFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
If File.Exists(ofdFile.FileName) = True Then
cn.ConnectionString = "Server=" & Servidor & ";uid=" & User & ";pwd=" & pwd & ";database=" & bd
cn.Open()
cm.Connection = cn
Dim ins As String
pbPOS.Value = 0
BCDbyte = My.Computer.FileSystem.ReadAllBytes(ofdFile.FileName)
For i As Integer = 0 To BCDbyte.Length - 1 Step 29
x = i
r = r + 1
For y As Integer = 0 To 28
Select Case y
Case 0 : ArtType &= CStr(BCDbyte(x))
Case 1, 2, 3, 4
HighDigit = Chr((BCDbyte(x) >> 4) + 48 )
LowDigit = Chr((BCDbyte(x) And 15) + 48 )
If y = 4 Then
Price &= CStr("." & HighDigit & LowDigit)
Else
Price &= CStr(HighDigit & LowDigit)
End If
Case 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
ArtName &= CStr(Chr(BCDbyte(x)))
Case 15 : ProdGroup &= CStr(BCDbyte(x) + 1)
Case 16 : TaxClass &= CStr(BCDbyte(x) + 1)
Case 17, 18, 19, 20
HighDigit = Chr((BCDbyte(x) >> 4) + 48 )
LowDigit = Chr((BCDbyte(x) And 15) + 48 )
DiscAmou &= CStr(HighDigit & LowDigit)
Case 21, 22
HighDigit = Chr((BCDbyte(x) >> 4) + 48 )
LowDigit = Chr((BCDbyte(x) And 15) + 48 )
DiscPerc &= CStr(HighDigit & LowDigit)
Case 23, 24, 25, 26, 27, 28
HighDigit = Chr((BCDbyte(x) >> 4) + 48 )
LowDigit = Chr((BCDbyte(x) And 15) + 48 )
EAN13 &= CStr(HighDigit & LowDigit)
If r = 28 Then
If r <> CInt(EAN13) Then
Dim First, Sec As String
Dim FirstAux, SecAux As Integer
Dim Res As Integer
For p As Integer = 0 To 11
Select Case p
Case 0 : First = EAN13([p])
FirstAux = CInt(First)
Case 1 : Sec = EAN13([p])
SecAux = CInt(Sec)
Case 2 : First = EAN13([p])
FirstAux = CInt(First) + FirstAux
Case 3 : Sec &= EAN13([p])
SecAux = CInt(Sec) + SecAux
Case 4 : First &= EAN13([p])
FirstAux = CInt(First) + FirstAux
Case 5 : Sec &= EAN13([p])
SecAux = CInt(Sec) + SecAux
Case 6 : First &= EAN13([p])
FirstAux = CInt(First) + FirstAux
Case 7 : Sec &= EAN13([p])
SecAux = CInt(Sec) + SecAux
Case 8 : First &= EAN13([p])
FirstAux = CInt(First) + FirstAux
Case 9 : Sec &= EAN13([p])
SecAux = CInt(Sec) + SecAux
Case 10
First &= EAN13([p])
FirstAux = CInt(First) + FirstAux
Case 11
Sec &= EAN13([p])
SecAux = (CInt(Sec) + SecAux) * 3
Res = FirstAux + SecAux
If (Res Mod 10 = 0) Then
EAN13 &= "0"
Else
For o As Integer = 1 To 9
If ((Res + o) Mod 10) = 0 Then
EAN13 &= ((Res + o) - Res)
Exit For
End If
Next
End If
End Select
Sec = ""
First = ""
Next
Sec = ""
First = ""
SecAux = 0
FirstAux = 0
End If
End If
End Select
x = x + 1
Next
ins = "INSERT INTO ARTIGO (Id_Artigo, Preco, Descricao, Id_Grupo, Id_Iva, CodigoBarras, Id_UnidadeMedida, Id_SubGrupo) VALUES (" & CInt(r) & ",'" & Price & "','" & Replace(ArtName, "'", "") & "'," & CInt(ProdGroup) & "," & CInt(TaxClass) & ",'" & EAN13 & "',1,1)"
cm.CommandText = ins
cm.ExecuteNonQuery()
pbPOS.Value = r
'ListBox1.Items.Add(ArtType & "|" & Price & "|" & ArtName & "|" & ProdGroup & "|" & TaxClass & "|" & DiscAmou & "|" & DiscPerc & "|" & EAN13)
ArtType = ""
Price = ""
ArtName = ""
ProdGroup = ""
TaxClass = ""
DiscAmou = ""
DiscPerc = ""
EAN13 = ""
Next
End If
End If
MessageBox.Show("Dados importados com sucesso.", "ConverterIT", MessageBoxButtons.OK, MessageBoxIcon.Information)
cumps