We help IT Professionals succeed at work.
Get Started

Help required to convert C++ Code to VBA in Ms Access

236 Views
Last Modified: 2020-03-17
I need help to convert the header 1 , 2 & commandID C++ Code into VBA  so that I can easily code them into a proper VBA serial Packet :
C++ codes
Header1 = The first byte of package header
0x1A

Open in new window

( the C++ code is 0x1A)
Header2 = The second byte of package header
Ox5D 

Open in new window

( the C++ code is Ox5D)
CommandID =
0x 02

Open in new window

as C++ code

Example of the VBA Code for the three above C++ codes

' First two bytes of data packet are always these
   
Const header1 = &H1A
    Const header2 = &H5D
    Const cmdSigning = 2

Open in new window


' Assemble the packet up to final CRC bytes
  dataString = Chr(header1) & Chr(header2) & Chr(cmdSigning) & Dec2Bin(Len(content), 4) & content

Please note the Json Part is 100% correct, its just the first three codes  1A, 5D & 02 are incorrect , that is where help is required here:


Current Dump results:

0000 =  1A 5D 02 00 00 07 75 7B 0D 0A 20 20 20 22 50 6F | ]u{   "Po
0010 =  73 56 65 6E 64 6F 72 22 3A 20 22 4E 65 63 74 6F | sVendor": "Necto
0020 =  72 20 50 72 69 6D 65 20 41 63 63 6F 75 6E 74 69 | r Prime Accounti
0030 =  6E 67 20 53 6F 6C 75 74 69 6F 6E 73 22 2C 0D 0A | ng Solutions",
0040 =  20 20 20 22 50 6F 73 53 6F 66 74 77 61 72 65 56 |    "PosSoftwareV
0050 =  65 72 73 69 6F 6E 22 3A 20 22 32 2E 30 2E 30 2E | ersion": "2.0.0.
0060 =  31 22 2C 0D 0A 20 20 20 22 50 6F 73 4D 6F 64 65 | 1",   "PosMode
0070 =  6C 22 3A 20 22 43 61 70 2D 32 30 31 37 22 2C 0D | l": "Cap-2017",
0080 =  0A 20 20 20 22 50 6F 73 53 65 72 69 61 6C 4E 75 |    "PosSerialNu
0090 =  6D 62 65 72 22 3A 20 22 31 30 30 31 30 30 30 30 | mber": "10010000
00A0 =  31 38 32 39 22 2C 0D 0A 20 20 20 22 49 73 73 75 | 1829",   "Issu
00B0 =  65 54 69 6D 65 22 3A 20 22 32 30 32 30 30 33 31 | eTime": "2020031
00C0 =  32 32 31 34 34 34 37 22 2C 0D 0A 20 20 20 22 54 | 2214447",   "T
00D0 =  72 61 6E 73 61 63 74 69 6F 6E 54 79 70 65 22 3A | ransactionType":
00E0 =  20 30 2C 0D 0A 20 20 20 22 50 61 79 6D 65 6E 74 |  0,   "Payment
00F0 =  4D 6F 64 65 22 3A 20 30 2C 0D 0A 20 20 20 22 53 | Mode": 0,   "S
0100 =  61 6C 65 54 79 70 65 22 3A 20 22 22 2C 0D 0A 20 | aleType": "", 
0110 =  20 20 22 4C 6F 63 61 6C 50 75 72 63 68 61 73 65 |   "LocalPurchase
0120 =  4F 72 64 65 72 22 3A 20 22 22 2C 0D 0A 20 20 20 | Order": "",   
0130 =  22 43 61 73 68 69 65 72 22 3A 20 22 41 64 6D 69 | "Cashier": "Admi
0140 =  6E 20 4D 61 6E 61 67 65 72 22 2C 0D 0A 20 20 20 | n Manager",   
0150 =  22 42 75 79 65 72 54 50 49 4E 22 3A 20 22 22 2C | "BuyerTPIN": "",
0160 =  0D 0A 20 20 20 22 42 75 79 65 72 4E 61 6D 65 22 |    "BuyerName"
0170 =  3A 20 22 22 2C 0D 0A 20 20 20 22 42 75 79 65 72 | : "",   "Buyer
0180 =  54 61 78 41 63 63 6F 75 6E 74 4E 61 6D 65 22 3A | TaxAccountName":
0190 =  20 22 22 2C 0D 0A 20 20 20 22 42 75 79 65 72 41 |  "",   "BuyerA
01A0 =  64 64 72 65 73 73 22 3A 20 22 22 2C 0D 0A 20 20 | ddress": "",  
01B0 =  20 22 42 75 79 65 72 54 65 6C 22 3A 20 22 22 2C |  "BuyerTel": "",
01C0 =  0D 0A 20 20 20 22 4F 72 69 67 69 6E 61 6C 49 6E |    "OriginalIn
01D0 =  76 6F 69 63 65 43 6F 64 65 22 3A 20 22 22 2C 0D | voiceCode": "",
01E0 =  0A 20 20 20 22 4F 72 69 67 69 6E 61 6C 49 6E 76 |    "OriginalInv
01F0 =  6F 69 63 65 4E 75 6D 62 65 72 22 3A 20 22 22 2C | oiceNumber": "",
0200 =  0D 0A 20 20 20 22 4D 65 6D 6F 22 3A 20 22 22 2C |    "Memo": "",
0210 =  0D 0A 20 20 20 22 49 74 65 6D 73 22 3A 20 5B 0D |    "Items": [
0220 =  0A 20 20 20 20 20 20 7B 0D 0A 20 20 20 20 20 20 |       {      
0230 =  20 20 20 22 49 74 65 6D 49 64 22 3A 20 31 2C 0D |    "ItemId": 1,
0240 =  0A 20 20 20 20 20 20 20 20 20 22 44 65 73 63 72 |          "Descr
0250 =  69 70 74 69 6F 6E 22 3A 20 22 46 75 72 69 74 79 | iption": "Furity
0260 =  20 44 72 69 6E 6B 20 6D 6C 73 20 33 35 30 22 2C |  Drink mls 350",
0270 =  0D 0A 20 20 20 20 20 20 20 20 20 22 42 61 72 43 |          "BarC
0280 =  6F 64 65 22 3A 20 31 34 2C 0D 0A 20 20 20 20 20 | ode": 14,     
0290 =  20 20 20 20 22 51 75 61 6E 74 69 74 79 22 3A 20 |     "Quantity": 
02A0 =  31 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 55 6E | 1,         "Un
02B0 =  69 74 50 72 69 63 65 22 3A 20 38 32 2E 37 36 2C | itPrice": 82.76,
02C0 =  0D 0A 20 20 20 20 20 20 20 20 20 22 44 69 73 63 |          "Disc
02D0 =  6F 75 6E 74 22 3A 20 30 2C 0D 0A 20 20 20 20 20 | ount": 0,     
02E0 =  20 20 20 20 22 54 61 78 4C 61 62 65 6C 73 22 3A |     "TaxLabels":
02F0 =  20 5B 0D 0A 20 20 20 20 20 20 20 20 20 20 20 20 |  [            
0300 =  22 41 22 0D 0A 20 20 20 20 20 20 20 20 20 5D 2C | "A"         ],
0310 =  0D 0A 20 20 20 20 20 20 20 20 20 22 54 6F 74 61 |          "Tota
0320 =  6C 41 6D 6F 75 6E 74 22 3A 20 39 36 2E 30 30 31 | lAmount": 96.001
0330 =  36 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 49 73 | 6,         "Is
0340 =  54 61 78 49 6E 63 6C 75 73 69 76 65 22 3A 20 74 | TaxInclusive": t
0350 =  72 75 65 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 | rue,         "
0360 =  52 52 50 22 3A 20 39 36 0D 0A 20 20 20 20 20 20 | RRP": 96      
0370 =  7D 2C 0D 0A 20 20 20 20 20 20 7B 0D 0A 20 20 20 | },      {   
0380 =  20 20 20 20 20 20 22 49 74 65 6D 49 64 22 3A 20 |       "ItemId": 
0390 =  32 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 44 65 | 2,         "De
03A0 =  73 63 72 69 70 74 69 6F 6E 22 3A 20 22 4D 69 78 | scription": "Mix
03B0 =  65 64 20 46 72 75 69 74 65 20 44 72 69 6E 6B 20 | ed Fruite Drink 
03C0 =  33 35 30 20 6D 6C 73 22 2C 0D 0A 20 20 20 20 20 | 350 mls",     
03D0 =  20 20 20 20 22 42 61 72 43 6F 64 65 22 3A 20 31 |     "BarCode": 1
03E0 =  36 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 51 75 | 6,         "Qu
03F0 =  61 6E 74 69 74 79 22 3A 20 31 2C 0D 0A 20 20 20 | antity": 1,   
0400 =  20 20 20 20 20 20 22 55 6E 69 74 50 72 69 63 65 |       "UnitPrice
0410 =  22 3A 20 38 32 2E 37 36 2C 0D 0A 20 20 20 20 20 | ": 82.76,     
0420 =  20 20 20 20 22 44 69 73 63 6F 75 6E 74 22 3A 20 |     "Discount": 
0430 =  30 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 54 61 | 0,         "Ta
0440 =  78 4C 61 62 65 6C 73 22 3A 20 5B 0D 0A 20 20 20 | xLabels": [   
0450 =  20 20 20 20 20 20 20 20 20 22 41 22 0D 0A 20 20 |          "A"  
0460 =  20 20 20 20 20 20 20 5D 2C 0D 0A 20 20 20 20 20 |        ],     
0470 =  20 20 20 20 22 54 6F 74 61 6C 41 6D 6F 75 6E 74 |     "TotalAmount
0480 =  22 3A 20 39 36 2E 30 30 31 36 2C 0D 0A 20 20 20 | ": 96.0016,   
0490 =  20 20 20 20 20 20 22 49 73 54 61 78 49 6E 63 6C |       "IsTaxIncl
04A0 =  75 73 69 76 65 22 3A 20 74 72 75 65 2C 0D 0A 20 | usive": true, 
04B0 =  20 20 20 20 20 20 20 20 22 52 52 50 22 3A 20 39 |         "RRP": 9
04C0 =  36 0D 0A 20 20 20 20 20 20 7D 2C 0D 0A 20 20 20 | 6      },   
04D0 =  20 20 20 7B 0D 0A 20 20 20 20 20 20 20 20 20 22 |    {         "
04E0 =  49 74 65 6D 49 64 22 3A 20 33 2C 0D 0A 20 20 20 | ItemId": 3,   
04F0 =  20 20 20 20 20 20 22 44 65 73 63 72 69 70 74 69 |       "Descripti
0500 =  6F 6E 22 3A 20 22 4F 72 61 6E 67 65 20 44 72 69 | on": "Orange Dri
0510 =  6E 6B 20 33 35 30 20 6D 6C 73 22 2C 0D 0A 20 20 | nk 350 mls",  
0520 =  20 20 20 20 20 20 20 22 42 61 72 43 6F 64 65 22 |        "BarCode"
0530 =  3A 20 31 33 2C 0D 0A 20 20 20 20 20 20 20 20 20 | : 13,         
0540 =  22 51 75 61 6E 74 69 74 79 22 3A 20 31 2C 0D 0A | "Quantity": 1,
0550 =  20 20 20 20 20 20 20 20 20 22 55 6E 69 74 50 72 |          "UnitPr
0560 =  69 63 65 22 3A 20 38 32 2E 37 36 2C 0D 0A 20 20 | ice": 82.76,  
0570 =  20 20 20 20 20 20 20 22 44 69 73 63 6F 75 6E 74 |        "Discount
0580 =  22 3A 20 30 2C 0D 0A 20 20 20 20 20 20 20 20 20 | ": 0,         
0590 =  22 54 61 78 4C 61 62 65 6C 73 22 3A 20 5B 0D 0A | "TaxLabels": [
05A0 =  20 20 20 20 20 20 20 20 20 20 20 20 22 41 22 0D |             "A"
05B0 =  0A 20 20 20 20 20 20 20 20 20 5D 2C 0D 0A 20 20 |          ],  
05C0 =  20 20 20 20 20 20 20 22 54 6F 74 61 6C 41 6D 6F |        "TotalAmo
05D0 =  75 6E 74 22 3A 20 39 36 2E 30 30 31 36 2C 0D 0A | unt": 96.0016,
05E0 =  20 20 20 20 20 20 20 20 20 22 49 73 54 61 78 49 |          "IsTaxI
05F0 =  6E 63 6C 75 73 69 76 65 22 3A 20 74 72 75 65 2C | nclusive": true,
0600 =  0D 0A 20 20 20 20 20 20 20 20 20 22 52 52 50 22 |          "RRP"
0610 =  3A 20 39 36 0D 0A 20 20 20 20 20 20 7D 2C 0D 0A | : 96      },
0620 =  20 20 20 20 20 20 7B 0D 0A 20 20 20 20 20 20 20 |       {       
0630 =  20 20 22 49 74 65 6D 49 64 22 3A 20 34 2C 0D 0A |   "ItemId": 4,
0640 =  20 20 20 20 20 20 20 20 20 22 44 65 73 63 72 69 |          "Descri
0650 =  70 74 69 6F 6E 22 3A 20 22 50 69 6E 65 61 70 6C | ption": "Pineapl
0660 =  65 20 20 44 72 69 6E 6B 20 33 35 30 20 6D 6C 73 | e  Drink 350 mls
0670 =  22 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 42 61 | ",         "Ba
0680 =  72 43 6F 64 65 22 3A 20 31 35 2C 0D 0A 20 20 20 | rCode": 15,   
0690 =  20 20 20 20 20 20 22 51 75 61 6E 74 69 74 79 22 |       "Quantity"
06A0 =  3A 20 31 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 | : 1,         "
06B0 =  55 6E 69 74 50 72 69 63 65 22 3A 20 38 32 2E 37 | UnitPrice": 82.7
06C0 =  36 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 44 69 | 6,         "Di
06D0 =  73 63 6F 75 6E 74 22 3A 20 30 2C 0D 0A 20 20 20 | scount": 0,   
06E0 =  20 20 20 20 20 20 22 54 61 78 4C 61 62 65 6C 73 |       "TaxLabels
06F0 =  22 3A 20 5B 0D 0A 20 20 20 20 20 20 20 20 20 20 | ": [          
0700 =  20 20 22 41 22 0D 0A 20 20 20 20 20 20 20 20 20 |   "A"         
0710 =  5D 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 54 6F | ],         "To
0720 =  74 61 6C 41 6D 6F 75 6E 74 22 3A 20 39 36 2E 30 | talAmount": 96.0
0730 =  30 31 36 2C 0D 0A 20 20 20 20 20 20 20 20 20 22 | 016,         "
0740 =  49 73 54 61 78 49 6E 63 6C 75 73 69 76 65 22 3A | IsTaxInclusive":
0750 =  20 74 72 75 65 2C 0D 0A 20 20 20 20 20 20 20 20 |  true,        
0760 =  20 22 52 52 50 22 3A 20 39 36 0D 0A 20 20 20 20 |  "RRP": 96    
0770 =  20 20 7D 0D 0A 20 20 20 5D 0D 0A 7D 38 F4       |   }   ]}8

Open in new window

Comment
Watch Question
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 35 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE