VAL

From QB64 Wiki
Revision as of 05:01, 27 July 2009 by 81.231.142.40 (talk) (Created page with 'VAL returns the number representation of a string. ''Example:'' :a$ = "33" :PRINT VAL("10") + VAL(a$) + 1 ''Returns:'' :44 ''Explanation:'' 10 + 33 + 1 = 44, the strings were…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

VAL returns the number representation of a string.

Example:

a$ = "33"
PRINT VAL("10") + VAL(a$) + 1

Returns:

44

Explanation:

10 + 33 + 1 = 44, the strings were converted to values.

You have to convert the string to values in order to use them in a mathematical expression also since mixing strings with numbers isn't allowed.

If VAL wasn't used the program would break with error, as you can't add the value 1 to a string, if the 1 was a string ("1") then the program would return "10331", but now since we used VAL the numbers were added as they should.


See also:

STR$ (function)