The function you were using returns the value as a string, so in my example, $X is a string - the value has quotes around it.

Val() converts strings to numbers, but is limited to Integers. What you are seeing is the result of "wrap" when the excess bits are dropped.

Because the size of your value exceeds the limit of Integer data, you need to employ double-precision math. Some languages have other (or even several) class names such as Real, Float, Single.. these simply reflect the maximum range that can be represented. The higher precision employed, the more data memory consumed, so languages like C have several options. Kix just offers Double and Integer.

So - you need to convert the string containing a large value to a double-precision value first. You need to recognize the size of your data and plan for it in the code (or adapt once you see the strange values!) One method is to use the CDbl() function, and another common "shortcut" is to multiply by 1.0, but the multiplier must come first - as so:
 Code:
$x = '160039239680'
$x ?
VAL($x) ?

CDbl($X) ?
1.0 * $X ?

Also, it's considered a matter of preference, but.. "?" represents a CR/LF sequence - same as @CRLF. It is not a shortcut for a "print" statement as in old versions of BASIC. If you place the "?" in front of your output statements, you will always start with a blank line and leave the cursor at the end of the output. Try this:
 Code:
CLS
For $X = 1 to 24
  ? $X
Next
Get $X
Where is the #1 displayed? Where is the cursor? Try
 Code:
CLS
For $X = 1 to 24
  $X ?
Next
Get $X
Now where is the #1 displayed? See how the leading "?" offsets the output? This can affect screen formatting as well as file data. In fact, not having a closing CRLF could affect some file-based applications. The CRLF sequence should follow your data instead of preceeding it.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D