- How to convert Strings with Val()
  - The Program
  - The Code:
  - The Source

# How to convert Strings with Val()

Val() converts a string into a datatype according to the content of the string.
So, if the string looks like a float, Val() makes a float out of it.
Val() uses the local language of your machine, which is defined via "locales".
See your enviroment with shell command "locales" or "echo $LANG".
So, at my machine 5,6 is a float (see picture!), because in germany the comma and not the point is used in decimal numbers.

## The Program

You can type in a string and the program converts with Val(), than the type of the converted variable is checked.
The result is displayed.

## The Code:

    STATIC PUBLIC SUB Main()
      hForm AS Fmain
      hForm = NEW Fmain
      hForm.show
    END

    PUBLIC SUB _new()
      TextLabel1.Text="Type in something that looks like an <br>" &
      "Integer, Float or Boolean"
    END

    PUBLIC SUB Button1_Click()
      x AS Variant
      x = Val(TextBox1.Text)

      IF IsBoolean(x) THEN
        Label1.Text="This is a Boolean!"
      ENDIF
      IF IsInteger(x) THEN
        Label1.Text="This is an Integer!"
      ENDIF
      IF IsFloat(x) THEN
        Label1.Text="This is a Float!"
      ENDIF
      IF IsString(x) THEN
        Label1.Text="This is a String!"
      ENDIF
    END

## The Source

Download