Function Returns wrong value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmdolcet69
    New Member
    • Sep 2007
    • 25

    Function Returns wrong value

    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?

    [CODE=vb]Public Function ByteDeg(ByVal _ReadingArrayLi st3 As ArrayList)
    Dim intindex As Integer
    For Each intarrayindex In _ReadingArrayLi st3
    LoByte_Value = _ReadingArrayLi st3(intindex) And &HFF&
    HiByte_value = _ReadingArrayLi st3(intindex) \ &H100 And &HFF&
    intindex = intindex + 1
    'table_upload_r eq()
    Next
    End Function[/CODE]
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by cmdolcet69
    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 _ReadingArrayLi st3 As ArrayList)
    Dim intindex As Integer
    For Each intarrayindex In _ReadingArrayLi st3
    LoByte_Value = _ReadingArrayLi st3(intindex) And &HFF&
    HiByte_value = _ReadingArrayLi st3(intindex) \ &H100 And
    &HFF&
    intindex = intindex + 1
    'table_upload_r eq()
    Next
    End Function

    try

    [CODE=vb]
    Public Function ByteDeg(ByVal _ReadingArrayLi st3 As ArrayList)
    Dim intindex As Integer
    dim intarrayindex
    For Each intarrayindex In _ReadingArrayLi st3
    LoByte_Value = intarrayindex And &HFF&
    HiByte_value = intarrayindex \ &H100 And
    &HFF&
    'table_upload_r eq()
    Next
    End Function[/QUOTE][/CODE]

    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

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by cmdolcet69
      ...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.

      Comment

      • cmdolcet69
        New Member
        • Sep 2007
        • 25

        #4
        Originally posted by Killer42
        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.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by cmdolcet69
          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...
          [CODE=vb]Type BytePair
          HiByte As Byte
          LoByte AsByte
          End Type[/CODE]...and then have the function return an array of type BytePair.

          Comment

          Working...