Available on:
See also: STR

VAL

The VAL command is a function that allows you to convert a string that represents a number into a integer numeric value. In other words, it takes a string that contains numbers and returns the corresponding numeric value.

The VAL command is very useful when working with user input, because the user often enters numbers as strings. For example, if we ask the user to enter their age, the input will be a string. In order to perform calculations with this age, we must first convert it to a number.

The VAL function reads the string from left to right and stops at the first character that is not a number. The VAL function ignores spaces at the beginning of the string. If the string does not begin with a number or contains only non-numeric characters, the VAL function returns zero.

SYNTAX

 = VAL(string)


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 PRINT VAL("123")


Used in:

ABBREVIATION: Va

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

VAL ↔ Va

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS