How to create a VBA function for CRC & clearing runtime error 424

nector

New Member
Joined
Jan 19, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
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

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
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Just a guess, use Next Itemize instead of just Next(?)
 
Upvote 0
Just a guess, use Next Itemize instead of just Next(?)

I did some reading and this probably isn't the cause of the problem. Can you remove your On Error Resume Next, run the code, and hit Debug when it fails and then tell us which line is highlighted in the editor (that is, which line is failing)?
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top