VAL/de
(→(**COPIED FROM ENGLISH PAGE**) =) |
(→Example 2) |
||
(3 intermediate revisions by one user not shown) | |||
Line 15: | Line 15: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Anmerkungen</span> = |
<div style="padding: 0px; margin: 0px 0px 0px 4px;"> | <div style="padding: 0px; margin: 0px 0px 0px 4px;"> | ||
{| width="567" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | {| width="567" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | ||
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
| valign="top" width="13%" style="width: 70px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="13%" style="width: 70px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | var | |
| valign="top" width="100%" style="width: 488px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 488px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Numerische Variable der der Wert von s zugewiesen wird. | |
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
| valign="top" width="13%" style="width: 70px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="13%" style="width: 70px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | s | |
| valign="top" width="100%" style="width: 488px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 488px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Zeichenkettenvariable. | |
|} | |} | ||
Line 36: | Line 36: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | 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. | |
| | ||
Line 62: | Line 62: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Siehe auch</span> = |
[[STR]] , [[HEXVAL]] , [[HEX]] , [[BIN]] , [[BINVAL]] , [[STR2DIGITS]] | [[STR]] , [[HEXVAL]] , [[HEX]] , [[BIN]] , [[BINVAL]] , [[STR2DIGITS]] | ||
Line 70: | Line 70: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Beispiel</span> = |
<br/><source lang="bascomavr"> | <br/><source lang="bascomavr"> | ||
− | $regfile = "m48def.dat" ' | + | $regfile = "m48def.dat" ' Mikrocontroller |
− | $crystal = 8000000 ' | + | $crystal = 8000000 ' Taktfrequenz |
− | $baud = 19200 ' | + | $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) ' | + | A = Val(s) 'Zeichenkette umwandeln |
Print A ' 123 | Print A ' 123 | ||
Line 94: | Line 94: | ||
</source> | </source> | ||
− | + | = <span class="f_Header">Beispiel 2</span> = | |
− | + | ||
− | = <span class="f_Header"> | + | |
<br/><source lang="bascomavr"> | <br/><source lang="bascomavr"> | ||
− | $regfile = "m48def.dat" ' | + | $regfile = "m48def.dat" ' Mikrocontroller |
− | $crystal = 8000000 ' | + | $crystal = 8000000 ' Taktfrequenz |
− | $baud = 19200 ' | + | $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 108: | Line 106: | ||
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 | Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 | ||
− | Const _VALCHECK=1 ' | + | Const _VALCHECK=1 ' Prüfung bei VAL() |
Dim A As Byte , S As String * 10 | Dim A As Byte , S As String * 10 | ||
S = "123" | S = "123" | ||
− | A = Val(s) ' | + | A = Val(s) 'Zeichenkette umwandeln |
Print A ; " ERR:" ; Err ' 123 | Print A ; " ERR:" ; Err ' 123 | ||
Latest revision as of 23:38, 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
Beispiel 2
$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 Const _VALCHECK=1 ' Prüfung bei VAL() Dim A As Byte , S As String * 10 S = "123" A = Val(s) 'Zeichenkette umwandeln Print A ; " ERR:" ; Err ' 123 S = "1234a5678" Dim L As Long L = Val(s) Print L ; " ERR:" ; Err End
Languages | English • Deutsch |
---|