Why will Val("&H") sometimes return a negative value?

by Solitaire (Login Solitaire1)
S

DIM stx AS STRING, num AS DOUBLE
CLS
INPUT "Enter a hex value: ", stx$
num = VAL("&H" + stx)
PRINT num

For example, entering AB34 will return -21758 instead of 43828.

How can the code be changed to display the correct answer?

Posted on Jun 7, 2012, 6:49 PM

Respond to this message   

Return to Index


Response TitleAuthor and Date
Re: Why will Val("&H") sometimes return a negative value? on Jun 7
 Thank you. More code added:Solitaire on Jun 8
  Re: Thank you. More code added: on Jun 8
   dnum is a double because...Solitaire on Jun 9
    Re: dnum is a double because... on Jun 9
     Val() is considered a legacy function.Solitaire on Jun 9
      VAL has nothing to do with INTEGERS in QB either on Jun 9
       VAL conversionSolitaire on Jun 10
      *Val() legacy ? but useful on Jun 10
LONG values, like INTEGERS use the top bit as the sign bit on Jun 7
All values greater than or equal to &H8000 (16-bit) or &H80000000& are negative numbersBill Gates on Jun 8