VAL/de

(Difference between revisions)
Jump to: navigation, search
(See also)
(Example)
Line 70: Line 70:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">Example</span> =
+
= <span class="f_Header">Beispiel</span> =
  
 
<br/><source lang="bascomavr">
 
<br/><source lang="bascomavr">
$regfile = "m48def.dat" ' specify the used micro
+
$regfile = "m48def.dat" ' Mikrocontroller
$crystal = 8000000 ' used crystal frequency
+
$crystal = 8000000 ' Taktfrequenz
$baud = 19200 ' use baud rate
+
$baud = 19200 ' Baudrate
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$swstack = 10 ' default use 10 for the SW stack
 
$swstack = 10 ' default use 10 for the SW stack
Line 84: Line 84:
 
Dim A As Byte , S As String * 10
 
Dim A As Byte , S As String * 10
 
S = "123"
 
S = "123"
A = Val(s) 'convert string
+
A = Val(s) 'Zeichenkette umwandeln
 
Print A ' 123
 
Print A ' 123
 
   
 
   
Line 93: Line 93:
 
End
 
End
 
</source>
 
</source>
 
 
  
 
= <span class="f_Header">Example 2</span> =
 
= <span class="f_Header">Example 2</span> =

Revision as of 23:36, 1 March 2013

Contents

Funktion

Wandelt eine Zeichenkettendarstellung einer Zahl in eine Zahl um.

 

 

Syntax

var = VAL( s)

 

 

Anmerkungen

var

Numerische Variable der der Wert von s zugewiesen wird.

s

Zeichenkettenvariable.

 

Es hängt vom Variablentyp ab welche Konvertierungsroutinen intern benutzt werden. Single- und Double-Konvertierungen benötigen mehr Programmspeicherplatz.

Bei Verwendung von INPUT verwendet der Compiler intern auch die VAL-Funktion.

Um Code zu sparen gibt es andere Umwandlungsroutinen wie zum Beispiel BINVAL und HEXVAL.

Sie könnten dem Compiler hinzugefügt werden aber das würde Overhead bedeuten weil sie möglicherweise nie benötigt werden.

Mit Zeichenketten als Eingabe oder beim INPUT Befehl ist die Zeichenkette dynamisch und deshalb würden alle Konvertierungs-Routinen benötigt werden.

 

Die VAL()-Funktion prüft nicht auf ungültige Zeichen. Wenn sie benutzt werden dann ergibt das falsche Ergebnisse oder 0.

Falls Sie eine Prüfung auf ungültige Zeichen wünschen dann können Sie die Konstante _VALCHECK mit dem Wert 1 hinzufügen.

Dadurch wird Code erzeugt, der eine ERR-Variable auf 0 oder 1 setzt. Wenn ungültige Zeichen erkannt werden dann gibt ERR 1 zurück.

Da VAL auch beim INPUT-Befehl benutzt wird geht das auch beim INPUT-Befehl.

 

 

 

Siehe auch

STR , HEXVAL , HEX , BIN , BINVAL , STR2DIGITS

 

 

Beispiel


$regfile = "m48def.dat" ' Mikrocontroller
$crystal = 8000000 ' Taktfrequenz
$baud = 19200 ' Baudrate
$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) 'Zeichenkette umwandeln
Print A ' 123
 
S = "12345678"
Dim L As Long
L = Val(s)
Print L
End

Example 2


$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
 
Const _VALCHECK=1 ' TEST VAL()
Dim A As Byte , S As String * 10
S = "123"
A = Val(s) 'convert string
Print A ; " ERR:" ; Err ' 123
 
S = "1234a5678"
Dim L As Long
L = Val(s)
Print L ; " ERR:" ; Err
End

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language