Dear All
I need help to create a fuction in vba to caculate CRC this used in rs 232 data writing , without this function nothing can be sent. I need for the below VBA Code
The last question goes as follows:
After receiving the data from the rs 232 , I want to iterate the Json string and parse the data into the table in Ms Access but the code below is giving runtime error 424 , object required , kindly help me to fix it:
I need help to create a fuction in vba to caculate CRC this used in rs 232 data writing , without this function nothing can be sent. I need for the below VBA Code
VBA Code:
Dim Start As String
Dim strTMP As String
Dim strLength As String, L As Long, L1 As Integer, L2 As Integer, L3 As Integer, L4 As Integer
strData = JsonConverter.ConvertToJson(transaction, Whitespace:=3) & Chr$(13)
L = Len(strData) 'Only length of content string. May be start, length and CRC should be added L = Len(strData) + 9 (or 7 without CRC)
L1 = L Mod 256
L2 = (L - L1) / 256 Mod 256
L3 = ((L - L1) / 256 - L2) / 256 Mod 256
L4 = (((L - L1) / 256 - L2) / 256 - L3) / 256 Mod 256
strLength = Chr(L4) & Chr(L3) & Chr(L2) & Chr(L1)
strTMP = Start & strLength & Chr(2) & strData
strTMP = strTMP & strData
'You need function for CRC calculation
strTMP = strTMP & CRC(strTMP)
lngStatus = CommWrite(intPortID, strTMP)
The last question goes as follows:
After receiving the data from the rs 232 , I want to iterate the Json string and parse the data into the table in Ms Access but the code below is giving runtime error 424 , object required , kindly help me to fix it:
Code:
' Read maximum of 64 bytes from serial port.
Dim Customers As Collection
Dim Itemize As Variant
lngStatus = CommRead(intPortID, strData, 14400)
Set rs = db.OpenRecordset("tblEfdReceiptsPOS")
If lngStatus > 0 Then
Set Customers = ParseJson(strData)
Z = 2
ElseIf lngStatus < 0 Then
Beep
MsgBox "Please note that there is no data to read", vbOKOnly, "The Comm Port has no data"
' Handle error.
On Error Resume Next
End If
' Process data.
For Each Itemize In Customers
With rs
.AddNew
rs![TPIN] = Itemize("TPIN")
rs![TaxpayerName] = Itemize("TaxpayerName")
rs![Address] = Itemize("Address")
rs![ESDTime] = Itemize("ESDTime")
rs![TerminalID] = Itemize("TerminalID")
rs![InvoiceCode] = Itemize("InvoiceCode")
rs![InvoiceNumber] = Itemize("InvoiceNumber")
rs![FiscalCode] = Itemize("FiscalCode")
rs![TalkTime] = Itemize("TalkTime")
rs![Operator] = Itemize("Operator")
rs![Taxlabel] = Itemize("TaxItems")("TaxLabel")
rs![CategoryName] = Itemize("TaxItems")("CategoryName")
rs![Rate] = Itemize("TaxItems")("Rate")
rs![TaxAmount] = Itemize("TaxItems")("TaxAmount")
rs![TotalAmount] = Itemize("TaxItems")("TotalAmount")
rs![VerificationUrl] = Itemize("TaxItems")("VerificationUrl")
rs![INVID] = Me.ItemSoldID
.Update
End With
Z = Z + 1
Next
rs.Close
Set rs = Nothing
Set db = Nothing
Set Customers = Nothing
' Reset modem control lines.
lngStatus = CommSetLine(intPortID, LINE_RTS, False)
lngStatus = CommSetLine(intPortID, LINE_DTR, False)
' Close communications.
Call CommClose(intPortID)
End Sub