<< Prev        Next >>

ID : 287

Val

Function

To convert string type data into numeric value.

Syntax

Val(string)

Guaranteed entry

String
Designate String Type data.

Return value

Return numeric type data.

Description

String type data are converted into numeric value.

If the data cannot be converted into a numeric value, 0 is returned.

If any character other than numbers is detected in a string, Val function stops reading. Val function recognizes prefix &H (hexadecimal) and &B (binary) that indicate the radix. Space, tab and line feed contained in the argument string are ignored.

Character to be ignored
Space, tab and line feed
Characters recognized as numbers
0-9; 0-9, a-f and A-F for hexadecimal; and 0 and 1 for binary
Character specially recognized
  • Radix prefixes "&B" and "&H" * Numbers are not recognized unless it is a leading character.
  • Signs "+" and "-" * Value is not recognized as numbers unless it is a leading character.
  • Exponent symbol "E"
  • Decimal point "." * This is recognized as a decimal point only when it is recognized as a leading character. If the radix prefix is attached, it is recognized as a character other than numbers.

Related Terms

Asc, Chr, SprintF, Left, Len, Mid, Right, InStr, Bin, Hex

Attention

-

Example

'!TITLE "Conversion from String to Numeric Value"
' Convert a string "&H20" into a numeric value (decimal 32)
Sub Sample_Val

  Dim aaa As Integer

  ' Convert a string "&H20" into a numeric value (decimal 32)
  aaa = Val( "&H20" )

  ' Display "32" on the message output window
  PrintDbg aaa

End Sub

ID : 287

<< Prev        Next >>