Information générale
Catégorie:
Fonctions API de Windows
Titre:
Moving a 16 bit value into a 32 bit value
Hello All,
I have a VB6.0 application where I reference two 16 bit PLC counters.
the one counter goes up to 32767, when that is reached, I then add
one to my second counter and set my first counter to 0.
I use the following code to move my two counters into a long
Dim Counter1 As Integer
Dim Counter2 As Integer
Dim a(3) As Byte
Dim c As Long
Counter1 = 32767
Counter2 = 0
a(0) = Counter1 And &HFF
a(1) = (Counter1 And &HFF00) / 256
a(2) = Counter2 And &HFF
a(3) = (Counter2 And &HFF00) / 256
CopyMemory c, a(0), 4
Let's assume that Counter1 = 32767, I will set it to 0 and increment Counter2 by one.
Counter1 = 0
Counter2 = 1
a(0) = Counter1 And &HFF
a(1) = (Counter1 And &HFF00) / 256
a(2) = Counter2 And &HFF
a(3) = (Counter2 And &HFF00) / 256
CopyMemory c, a(0), 4
The value for c is now 65536 but I would expect it to be 32768
can someone tell me what I am doing wrong??
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement