Announcement

Collapse
No announcement yet.

Logical AND and variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logical AND and variables

    Hi

    Very interesting:

    DIM Var1 as WORD
    Var1 = 12338

    MSGBOX STR$(Var1 And 255) Result --> 28
    MSGBOX STR$(12338 And 255) Result --> 50 << this is what I expect

    Thanks

    Eric Kelderman


    ------------------
    Eric Kelderman
    www.dlog.nl

  • #2
    Eric --

    I get 50 and 50. Which compiler are you using? Which version?

    -- Eric


    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>
    "Not my circus, not my monkeys."

    Comment


    • #3
      I get 50 too...

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Eric

        I see I wasn't complete.
        The actuall variable def was a word array where Var1(0) == 12338

        If I do (Var1(0) And 255) I get 28, sometimes 68 ???

        If I do:
        Dim I as Word
        I = Var1(0)
        I and 255 the result is 50...

        I'm confused but it works.
        Could it be that the brackets in the array causes miscalculation?

        I use PB6, July 2 1999 Exe date.

        Thanks
        Eric




        ------------------
        Eric Kelderman
        www.dlog.nl

        Comment


        • #5
          OK

          Once again now a bit closer to the real problem which includes a pointer too

          TYPE M1S
          M1Data(0 TO 56) AS WORD
          END TYPE

          ===== This is fine


          FUNCTION GetMemoLicense() EXPORT AS INTEGER

          DIM I1 AS WORD, I2 AS WORD
          DIM M1Struct AS M1S

          M1Struct.M1Data(0) = 12338

          I1 = m1struct.m1data(0)
          I2 = I1
          I1 = (I1 AND 255)
          MSGBOX CHR$(I1)+STR$(I2)+STR$((I2-I1)/256)

          END FUNCTION


          ===== I2 is getting different values from I1 immediatly after assigning the value I2 = I1


          FUNCTION GetMemoLicense() EXPORT AS INTEGER

          DIM P1 AS LONG, P2 AS LONG, P3 AS LONG, P4 AS LONG
          DIM I1 AS WORD, I2 AS WORD
          DIM M1Struct AS M1S

          P1 = 0
          P2 = 56
          P4 = VARPTR(M1Struct)
          CALL Hasp(50, 0, 0, PLa, PLb, P1, P2, P3, P4) <<-- P4 = Pointer to M1Struct

          I1 = m1struct.m1data(0) <<-- How do I get reliable data from M1Struct ?????
          I2 = I1
          I1 = (I1 AND 255)
          MSGBOX CHR$(I1)+STR$(I2)+STR$((I2-I1)/256)
          |--- This I2 is 6952 ???..??? I expected 12338

          END FUNCTION




          ------------------
          Eric Kelderman
          www.dlog.nl

          Comment


          • #6
            Seems fine here. Perhaps there is a problem with the Hasp call?

            ------------------
            Tom Hanlin
            PowerBASIC Staff

            Comment


            • #7
              Code:
              P4 = VARPTR(M1Struct)
              CALL Hasp(50, 0, 0, PLa, PLb, P1, P2, P3, P4) <<-- P4 = Pointer to M1Struct
              Most (all I've seen) pointers are passed BY VALUE.

              In the absence of a DECLARE or the procedure header for Hasp using a "BYVAL P4", the call line shown will pass the ADDRESS of P4, not the value.

              Either try a declare, or use
              Code:
              CALL Hasp(50, 0, 0, PLa, PLb, P1, P2, P3, BYVAL P4) <<-- P4 = Pointer to M1Struct
              You might check the rest of the parameters for BYVAL, BYREF etc.


              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X