By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Function Returns wrong value

P: 25
Ok taking this code below when I look at my LoByte and HiByte value
the numbers don't make sense.
I pass the first arraylist(index) into this function which is 3595 integer. I should get a Lobyte as 149 and a hibyte as 53.
However i get a lobyte as 11 and hibyte as 14

What am I doing wrong?

Expand|Select|Wrap|Line Numbers
  1. Public Function ByteDeg(ByVal _ReadingArrayList3 As ArrayList) 
  2.   Dim intindex As Integer 
  3.   For Each intarrayindex In _ReadingArrayList3 
  4.     LoByte_Value = _ReadingArrayList3(intindex) And &HFF& 
  5.     HiByte_value = _ReadingArrayList3(intindex) \ &H100 And &HFF& 
  6.     intindex = intindex + 1 
  7.     'table_upload_req() 
  8.   Next 
  9. End Function
Sep 14 '07 #1
Share this Question
Share on Google+
4 Replies


kadghar
Expert 100+
P: 1,295
Ok taking this code below when i look at my LoByte and HiByte value
the numbers dont make sense.
I pass the first arraylist(index) into this function which is 3595
integer
i should get a Lobyte as 149 and a hibyte as 53
however i get a lobyte as 11 and hibyte as 14

what im i doing wrong.


Public Function ByteDeg(ByVal _ReadingArrayList3 As ArrayList)
Dim intindex As Integer
For Each intarrayindex In _ReadingArrayList3
LoByte_Value = _ReadingArrayList3(intindex) And &HFF&
HiByte_value = _ReadingArrayList3(intindex) \ &H100 And
&HFF&
intindex = intindex + 1
'table_upload_req()
Next
End Function

try

Expand|Select|Wrap|Line Numbers
  1. Public Function ByteDeg(ByVal _ReadingArrayList3 As ArrayList) 
  2.         Dim intindex As Integer 
  3.         dim intarrayindex
  4.         For Each intarrayindex In _ReadingArrayList3 
  5.             LoByte_Value = intarrayindex And &HFF& 
  6.             HiByte_value = intarrayindex \ &H100 And 
  7. &HFF& 
  8.             'table_upload_req() 
  9.         Next 
  10.     End Function[/quote]
Also i'll recomend you to use a procedure instead of a function, just put it as a sub and call it, since "in theory" a function should trhow a result with the same name.

But im just thinking out loud, that wont change the functionality.

HTH
Sep 14 '07 #2

Expert 5K+
P: 8,434
...I pass ... 3595 ... should get a Lobyte as 149 and a hibyte as 53. However I get a lobyte as 11 and hibyte as 14
What am I doing wrong?
I'm happy to report that what you're doing wrong is blaming the computer. :D

It's your own calculation that is wrong, not the function.

Decimal 3595 = Hex 0E0B. That is, high byte 0E (14) and low byte 0B (11).

High/low byte values of 53 and 149 would make hex 3595 (hm... curious coincidence, that) which is equivalent to the decimal value 13,717.

Now, if you were passing the value &h3595 and getting back then 14/11 then I'd be worried.
Sep 15 '07 #3

P: 25
I'm happy to report that what you're doing wrong is blaming the computer. :D

It's your own calculation that is wrong, not the function.

Decimal 3595 = Hex 0E0B. That is, high byte 0E (14) and low byte 0B (11).

High/low byte values of 53 and 149 would make hex 3595 (hm... curious coincidence, that) which is equivalent to the decimal value 13,717.

Now, if you were passing the value &h3595 and getting back then 14/11 then I'd be worried.
Killer42,
How can i convert an arraylist of decimal integer let start easy and take the first value of 4096 so that i can pass the Lobyte first and then the hibyte.

The protocol need to be value range 0x0000 - 0x0FF7, where the Lobyte is sent first. this is so confusing im losing it.

Please help.
Sep 15 '07 #4

Expert 5K+
P: 8,434
How can i convert an arraylist of decimal integer let start easy and take the first value of 4096 so that i can pass the Lobyte first and then the hibyte.

The protocol need to be value range 0x0000 - 0x0FF7, where the Lobyte is sent first. this is so confusing im losing it.
Um... I don't actually know what an arraylist is.

But assuming it works like an old-fashioned array, I think your existing function should be fine, You just need to tell the function to return an array. Um... how about making it an array of a user-defined type which contains your two byte values. In VB6 terms,you could do something like...
Expand|Select|Wrap|Line Numbers
  1. Type BytePair
  2.   HiByte As Byte
  3.   LoByte AsByte
  4. End Type
...and then have the function return an array of type BytePair.
Sep 15 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.