Console INPUT
Syntax
Syntax: INPUT [prompt$;] variable
Source: pb_cg_emit_read_console_line (pb_codegen.c:5266)
Description
Reads a line of text from the console (stdin) into a variable. If a prompt string followed by a semicolon is provided, it is displayed to the console before reading input. The input is read via ReadFile from the standard input handle, NUL-terminated, and trailing CR/LF characters are stripped. If the target variable is numeric, the input string is automatically converted with VAL().
Parameters
| Parameter | Description |
prompt$ | (Optional) A string prompt displayed before reading. Follow with ; to suppress newline, or , to add a question mark. |
variable | The variable to receive input. Can be STRING or numeric (LONG, SINGLE, DOUBLE, etc.). Numeric variables trigger automatic VAL() conversion. |
Example
LOCAL name$ AS STRING
LOCAL age AS LONG
INPUT "Enter your name: "; name$
INPUT "Enter your age: "; age
PRINT "Hello "; name$; ", you are "; age; " years old."
Interactive Session
Enter your name: Alice
Enter your age: 30
Hello Alice, you are 30 years old.
PILOT A: (Accept) Lowering
The PILOT A: command compiles to console INPUT. The compiler maps PILOT variables to BASIC variables before lowering:
PILOT-to-BASIC Mapping
| PILOT Command | Generated PowerBASIC |
A: | INPUT a$ |
A: $NAME | INPUT name$ |
A: #COUNT | INPUT temp$ : count# = VAL(temp$) |
Generated Assembly
Console Input via ReadFile
; 1. Optional prompt via PRINT
; (if prompt present)
; 2. Read from stdin
mov rcx, -10 ; STD_INPUT_HANDLE
call [__imp_GetStdHandle]
mov rcx, rax ; console input handle
lea rdx, [rbp - buffer_offset] ; buffer to read into
mov r8, 1024 ; max bytes (typically 256-1024)
lea r9, [rbp - input_count_offset] ; &bytesRead
mov [rsp + 32], 0 ; lpOverlapped = NULL
call [__imp_ReadFile]
; 3. NUL-terminate the input
mov r10, [rbp - input_count_offset] ; bytes actually read
lea r11, [rbp - buffer_offset]
add r11, r10
mov byte [r11], 0 ; buffer[bytesRead] = 0
; 4. Strip trailing CR/LF
; (if present in the buffer)
; 5. Assign to target variable
; For STRING: copy to local string buffer
; For numeric: VAL() conversion
VAL() Implementation Details
; When INPUT targets a numeric variable, the compiler generates:
; 1. Read string into temporary buffer
; 2. Call strtod (for SINGLE/DOUBLE) or strtol (for LONG/INTEGER)
; Example: INPUT age (LONG)
lea rcx, [rbp - temp_buffer] ; string to parse
xor rdx, rdx ; endptr = NULL
mov r8, 10 ; base = 10
call [__imp_strtol] ; RAX = parsed integer
mov [rbp - age_offset], rax ; store into target variable
; For floating point (SINGLE/DOUBLE):
lea rcx, [rbp - temp_buffer]
xor rdx, rdx
call [__imp_strtod] ; XMM0 = parsed double
movsd [rbp - double_offset], xmm0 ; store into target
Imported WinAPI Functions
| Function | DLL | Purpose |
GetStdHandle | kernel32.dll | Obtain handle to standard input stream |
ReadFile | kernel32.dll | Read raw bytes from the console input buffer |
strtod | msvcrt.dll | Convert string to double precision float |
strtol | msvcrt.dll | Convert string to signed long integer |