Syntax:
var = StringToLong(string) 'Supports decimal Long range strings only.Command Availability:
Available on all microcontrollers.
Explanation:
The StringToLong function extracts a number from a string variable and stores it in a Long variable. One potential use is reading numbers
that are sent in ASCII format over a serial connection.
StringToLong will not extract a value from a hexadecimal string.
Example 1:
' ----- Configuration
'Chip Settings.
#chip 16f18855,32
#Config MCLRE_ON
; ----- Define Hardware settings
'Set the PPS of the RS232 ports.
UNLOCKPPS
RC0PPS = 0x0010 'RC0->EUSART:TX;
RXPPS = 0x0011 'RC1->EUSART:RX;
LOCKPPS
; ----- Constants
#define USART_BAUD_RATE 19200
#define USART_TX_BLOCKING
; ----- Variables
dim longvar as long
longvar = 0
; ----- Main body of program commences here.
#option Explicit
do
wait 100 ms
Longvar = StringToLong( "255" ) ' <<< the StringToLong instruction
HSerPrint Longvar
HSerPrintCRLF
wait 1 s
loop
endKey line: Longvar = StringToLong( "255" ) — parses the decimal digits in the literal string "255" and stores the resulting long value in Longvar.
See Also:
- StringToByte — related command in the same category
- StringToSingle — related command in the same category
- LongToString — the inverse conversion

