11 - 396 11 - 396
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
VAL
Function
VALue
• Returns the value represented by a character string.
VAL(<character string expression>)
Syntax
character string expression
• • • •
Specify the character string to be converted into a
numeric expression.
Examples
A=VAL("123")
• • • •
Assigns the value represented by the string "123" to A.
Description
• The VAL function returns the value represented by a character string.
When a decimal string is specified
The first character in the string must be either space, +, , or a digit.
Specify digits only from the second character and onward.
Space, line feed, and tab characters exist in the string are ignored. In addition, if a
character that does not represent a numeric value is included, all characters from that
place to the end of the string are ignored.
Example
PRINT VAL(" - 1 2 3" ) -123
PRINT VAL(" 12A3" ) 12
When an octal string is specified
The first and second characters in the string must be the "&0" characters, which indicate
an octal value.
Specify digits only from the third character and onward.
Space, line feed, and tab characters exist in the string are ignored. In addition, if a
character that does not represent a numeric value is included, all characters from that
place to the end of the string are ignored.
Example
Octal
PRINT VAL(" &01 2 3" )
83 (123)
PRINT VAL(" &012A3" )
10 (12)
When a hexadecimal string is specified
The first and second characters in the string must be the "&H" characters, which indicate a
hexadecimal value.
Specify digits and characters from A to F only from the third character and onward.
If characters other than digits and A to F are included in the string after the third character,
all characters from that place to the end of the string are ignored.
Example
Hexadecimal
PRINT VAL(" &H1A 2C" )
26 (1A)
PRINT VAL(" &H1A2!C" )
418 (1A2)
• 0 is returned if the first and second characters are not the prescribed characters.
• The VAL function is used to perform the calculation in double-precision.