input

Prev Next

Function Names

input

Description

This function prompts a message on the screen (asking for user input) and then expects user input for a variable. Type and value checking can be enabled if needed, e.g. numbers only, integers with in a specific range, etc.

Call as: function

Restrictions

Indirect parameter passing is disabled.

Parameter count

0-3

Parameters

No.TypeDescription
1
input
string Prompt

The prompt will be displayed before input is requested

Opt. 2
input
string Checked value type

Use one of the following values:

string A string is expected. Actually, all inputs (even number, true, false, {a,b,}) are treated Stringly. No input is rejected for its contents.
numeral A numeral is expected
integer An integer is expected (no digits behind decimal point)
character Expects exactly 1 character. Blank inputs are rejected as well as inputs containing more than 1 character.
boolean Expects boolean value true or false. Following replies will be translated: true, t, yes, y, 1 ='true'; false, f, no, n, 0 for = 'false'. Input is not case sensitive.
date Valid and unambiguous date expected
time Valid time expected (e.g. hh:mm, hh:mm:ss)
date and time Expects combination of date and time

If the entered value does not match with the type, then the user will be requested to repeat the input.

Default value: string
Opt. 3
code
comparison expression
:string
Validation expression

If the entered value does not match with the type, then the user will be requested to repeat the input.

This parameter is a piece of code typically found on the right-hand side of a comparison with '=' or '<>'. Single values, ranges (e.g. 3..5), multiple values separated by commas are supported. For text comparison, wildcards are supported if the string is of type softquoted string.

Default value: true (no limitations)

Return value

TypeDescription
valid types Entered value

The value entered is returned, using the appropriate type.

Examples

    a[] = input("Enter both date and time: ", date and time  );
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

    a[] = input("Enter any value: ");
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

    a[] = input("Enter any integer greater than or equal to 3: ", integer, >=3);
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

    a[] = input("Enter one lower-case latin character: ", character, 'a'..'z');
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

    a[] = input("Enter a boolean value (true, false, y, n, ... ): ", boolean);
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

    a[] = input("Enter a date in 2020: ", date, date(01.01.2020)..date(31.12.2020) );
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

    a[] = input("Enter a time before 15:00 ", time, <time("15:00") );
    echo("Entered value is : ", a[],"   The type is : ", type (a[]) );

Output

Try it yourself: Open LIB_Function_input.b4p in B4P_Examples.zip. Decompress before use.

See also

input to complete
input quick