VAL

Top  Previous  Next

Action

Converts a string representation of a number into a number.

 

 

Syntax

var = VAL( s)

 

 

Remarks

Var

A numeric variable that is assigned with the value of s.

S

Variable of the string type.

 

It depends on the variable type which conversion routine will be used. Single and Double conversion will take more code space.

When you use INPUT, internal the compiler also uses the VAL routines.

In order to safe code, there are different conversion routines. For example BINVAL and HEXVAL are separate routines.

While they could be added to the compiler, it would mean a certain overhead as they might never be needed.

With strings as input or the INPUT statement, the string is dynamic and so all conversion routines would be needed.

 

 

See also

STR , HEXVAL , HEX , BIN , BINVAL

 

 

Example

$regfile = "m48def.dat"                                   ' specify the used micro

$crystal = 8000000                                         ' used crystal frequency

$baud = 19200                                               ' use baud rate

$hwstack = 32                                               ' default use 32 for the hardware stack

$swstack = 10                                               ' default use 10 for the SW stack

$framesize = 40                                             ' default use 40 for the frame space

 

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

 

Dim A As Byte , S As String * 10

S = "123"

A = Val(s)                                                 'convert string

Print A                                                     ' 123

 

S = "12345678"

Dim L As Long

L = Val(s)

Print L

End