vYQmG‖Val Function

Contents
QEP8g‖

# 6GkjG‖Val Function

VDZFx‖Use the Val function to convert a string that represents a number into numeric data type.

aQ5EY‖The string passed to the Val function is locale-independent. This means that commas are interpreted as thousands separators and a dot is used as the decimal separator.

### FVEx2‖Syntax:

        Rk6u2‖Val (Text As String)

### bBBqF‖Return type:

Gi4Ag‖Double

### WADQ4‖Parameters:

DmE2F‖Text: String that represents a number.

e9c9u‖If only part of the string contains numbers, only the first appropriate characters of the string are converted. If the string does not contain any numbers then Val returns 0.

### SEjHR‖Error codes:

5 Invalid procedure call

### EFSA4‖Example:

        Sub ExampleVal
            MsgBox Val("123.1") + 1 ' 124.1
        uA3WQ‖    ' Below 123,1 is interpreted as 1231 since "," is the thousands separator
            MsgBox Val("123,1") + 1 ' 1232
        h7GqE‖    ' All numbers are considered until a non-numeric character is reached
            MsgBox Val("123.4A") ' 123.4
        AiJD6‖    ' The example below returns 0 (zero) since the string provided does not start with a number
            MsgBox Val("A123.123") ' 0
        End Sub

Related Topics

Str Function

Please support us!