I am trying to take a value from memory and mask this value so I can
then set a number of bits in the value and then return it to memory.
I read the value from memory and mask it. When I read the value from
memory I return a value for ex. Hex FFFF. When I mask this value the
final value turns out to be FFFF FFFF. How can this be? Also, I
cannot change bit 15 unless I use 65535 as the value for the constant.
If I use &HFFFF it will not change bit 15. The same is true in the
reverse for bits 0-14. Any suggestions.
'make the mask based on the number of bits the operator needs set
num = 0
for i = cint(startbit) to cint(endbit)
num = (2 ^ i) + num
next
makemask = num
memoryValue = SMActiveXObj.peekInt16ArrayElement(offsetValue,
cint(word))
'create mask and set bits for desired range. Remaining bits will
remain
'unchanged
constant = 65535 '&HFFFF
mask = makemask XOR constant
currentData = mask AND memoryValue
data = &H00FF 'or whatever value the operator wants set.
'set the data to send back to memory
setData = currentData OR data
setValue = SMActiveXObj.pokeInt16ArrayElement(offsetValue, cint(word),
setData)
Why go through all the trouble typecasting ?
Your intermediate calculations will allways be correct as long as long as
you only use the logical operators, and if the
SMActiveXObj.pokeInt16ArrayElement function can't tolerate the excessive
highorder bits (which - without knowing the function - I'm rather sure it
will) you can mask the value using a MOD &H10000 just before passing it to
the function.
Best regards
Johnny Nielsen