Results 1 to 2 of 2

Thread: calculation failure?

  1. #1

    calculation failure?

    hello. anybody can check this very little code example? the result for "less -10" I don't understand. thanks for testing.

    ' Empty GUI script created on 07-15-2011 11:13:22 by (ThinAIR)
    Uses "console"
    Function TBMain() As Long
    MsgBox 0, alittle(1)
    End Function

    Function alittle (less As DWord) As Long
    Local a As Integer
    Local b As Integer less = -10 ' ?
    'less = 10 ' ok
    a = 2 b = 200
    Function = a*b+less
    End Function
    ' a) result for less = 10 : 410 ok
    ' b) result for less = -10 : 4294967686 ?
    there are few people they are really programming with thinbasic at the moment. background could be summer time?

    bye, largo
    Attached Files Attached Files
    Last edited by largo_winch; 19-07-2011 at 12:08.

  2. #2
    Hi Largo,

    You have made "less" an unsigned integer by using "Dword" as its type.
    Assigning a negative value will be interpreted as a twos complement value thus:

    -1 is &HFFFFFFFF
    -2 is &HFFFFFFFE
    -10 is &HFFFFFFF6

    Try using "Long" instead of "Dword"

    Charles


Similar Threads

  1. Selecting "Nothing" in an empty control causes a hang/failure.
    By ISAWHIM in forum UI (User Interface)
    Replies: 25
    Last Post: 29-09-2008, 03:14

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •