Guest Guest_Mike Posted September 29, 2004 Report Posted September 29, 2004 I got to fetch and poke data to an FX2n PLC. I'm getting 32 bit register data that I get in terms of 2 signed words (lsw and msw) that I need to put back together as a Dword. I also need to take a Dword and figure out the 2 words that make it and send back to the PLC. It's MX Component and VB6. I got a formula but it does not work if the msw is a negative integer? Any ideas? I need to do the conversion in VB6. Thanks, Mike Quote
panic mode Posted September 30, 2004 Report Posted September 30, 2004 I'm not sure I understand it correctly but it should be just a simple bit manipulation like this: Public Function ConvertToDINT(intA As Integer, intB As Integer) As Long Dim intC As Long If intA < 0 Then intC = 32768 intA = intA And &H7FFF intC = CLng(intB) * (2 ^ 16) + intC + intA ConvertToDINT = intC End Function This should combine two 16-bit integers into DINT. Just do the same steps backwards to convert DINT into two INTs. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.