Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Moving a 16 bit value into a 32 bit value
Message
De
23/02/2006 17:58:04
 
 
À
Tous
Information générale
Forum:
Visual Basic
Catégorie:
Fonctions API de Windows
Titre:
Moving a 16 bit value into a 32 bit value
Divers
Thread ID:
01098724
Message ID:
01098724
Vues:
46
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
Fil
Voir

Click here to load this message in the networking platform