Returns the requested input of a user from dialog. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
Input(caption, prompt [, defaultValueExpr] [,type] [,properties] [,valuesExpr])
caption is a string that will appear as the title in the Input dialog.
prompt is a string that displays text directly above the input edit box, showing what is expected for input. You can use an underscore (_) as an accelerator key.
defaultValue is an optional value returned if nothing is entered. It is shown as a value in the input edit box. It should be of the same variable type as expected for the return value.
type is an optional value described below to determine which type of input is requested. The default value is a string.
properties is an optional string parameter that can specify key-value pairs of items such as HelpText, MinimumValue for a number, ValidationPattern, etc.
"MinimumValue=1;MaximumValue=10;HelpText=Enter a value between 1 and 10"
property | Description |
---|---|
MinimumValue | MinimumValue for a number. |
MaximumValue | MaximumValue for a number. |
HelpText | Used as a tool-tip on a control |
CancelledValue | Value to be set if you cancel a dialog. |
ValidationPattern and ValidationMessage |
Applies to: string, any Combo-Box type but only when IsEditable=True ValidationPattern: regular expression against which the input is validated. ValidationMessage: message to show when input does not match the pattern. |
NumberFormat |
Applies to numeric types - integer, shortint, largeint, float, decimal. For example,
For more information on how to use number format strings, see the MapBasic Help Topic for the function Format$() |
AllowNoSelection |
Applies to Combo-boxes. True or False - if True, then no input(selection) is required on the combo-box. If False (default), then a Validation error is shown, and the user must choose an item from the Combo-box. |
valuesExpr is an optional value that generates a list of choices or restrictions on the range of values allowed.
Return Value
Any standard variable type like String, Integer, LargeInt, Float, Logical, Date, DateTime, or Time.
Example
Dim RetVal as Integer
RetVal = Input$("My Input Caption", "Input an integer", 999, "This is a help topic")
print RetVal
Description
The Input() function provides a simple way to request input from user for use in an application.
type | valuesExpr | Description | properties | Return Value | Examples |
---|---|---|---|---|---|
integer |
The return value will be of type integer. Only valid integers can be entered. The DefaultExpr is evaluated and if it can be converted to an integer, it is used as the initial value. |
MinimumValue MaximumValue CancelledValue HelpText NumberFormat |
Integer |
MinimumValue=1; MaximumValue=10 print input("MapInfo","test",12345, "integer","NumberFormat="",#""") |
|
smallint |
The return value will be of type smallint The DefaultExpr is evaluated and if it can be converted to a smallint, it is used as the initial value. |
MinimumValue MaximumValue CancelledValue HelpText NumberFormat |
SmallInt | ||
largeint |
The return value will be of type largeint. The DefaultExpr is evaluated and if it can be converted to a largint, it is used as the initial value. |
MinimumValue MaximumValue CancelledValue HelpText NumberFormat |
LargeInt | ||
float |
The return value will be of type float. The DefaultExpr is evaluated and if it can be converted to a float it is used as the initial value. |
MinimumValue MaximumValue CancelledValue HelpText NumberFormat |
Float | print input ("MapInfo", "test", 12345.678, "float", "NumberFormat=""$, #.##;;(,#.##)""") | |
file |
Uses the MapBasic FileOpenDlg() function. .EXT is the type of file extension. The DefaultExpr is evaluated and is used as the initial value. |
Extension CancelledValue HelpText |
String |
Extension=TAB Extension=WOR Extension=CSV |
|
table | expr |
expr is a logical MapBasic expression that is evaluated for each open table. If it returns TRUE, the table is included in the drop-down list. ScriptContext(2) is substituted with the name (alias) of the table being evaluated. If no expr is given, then all open tables are listed. If there is an error evaluating the expression, then the table is included. The DefaultExpr is evaluated and if it matches the alias of one of the listed tables, that table is pre-selected. The return value is the alias of the selected table or empty string if none. |
CancelledValue HelpText AllowNoSelection |
String |
TableInfo(ScriptContext(2), TAB_INFO_DOMINANT_OBJECT_TYPE)=2 Or TableInfo(ScriptContext(2), TAB_INFO_DOMINANT_OBJECT_TYPE)=3 Like(ScriptContext(2), "%U%", "") dim t as string t = Input("Input", "_Table:", "usa", "table", "HelpText=Pick a dang table", "TableInfo(ScriptContext(2), TAB_INFO_DOMINANT_OBJECT_TYPE)=2") select * from t t = Input("Input", "_Table:", "usa", "table", "HelpText=Pick a dang table", "Like(ScriptContext(2), ""%U%"", """")") select * from t |
column | tableColExpr | tableColExpr is a logical MapBasic expression that is evaluated for each open table and each column. If it returns TRUE, the table.column is included in the drop-down list. ScriptContext(2) is substituted with the alias of the table being evaluated and ScriptContext(3) is substituted with the column alias, If no expr is given, then the columns from all open tables are listed. If there is an error evaluating the expression, then the table is included. The DefaultExpr is evaluated and if it matches the alias of one of the listed columns, that column is pre-selected. The return value is the alias of the selected column or empty string if none. |
CancelledValue HelpText AllowNoSelection |
Alias |
Open Table "C:\work\Data\USA\USA.TAB" dim col as Alias col = Input("Input", "_Column:", "URL", "column", "", "TableInfo(ScriptContext(2), TAB_INFO_NAME)=""USA"" And ColumnInfo(ScriptContext(2), ScriptContext(3),COL_INFO_TYPE)=1") browse col from usa |
logical |
A check-box is displayed. The DefaultExpr is evaluated and if it can be converted to a logical, it is used as the initial value. |
CancelledValue HelpText |
Logical | ||
date | An editable Date Picker is displayed. The DefaultExpr is evaluated and if it
can be converted to a date, it is used as the initial value. A range can be specified via a string in the ValesExpr |
MinimumValue MaximumValue |
Date | MinimumValue=19960101; MaximumValue=19960531 | |
string |
This is an editable text-box. The DefaultExpr is evaluated and is used as the initial value. If a MaximumLength is specified, it is the number of characters you can enter. The default REGEX pattern is ".*". |
ValidationPattern ValidationMessage MaximumLength CancelledValue HelpText |
String |
MaximumLength=5 ValidationPattern=10:[^A-Z]+ Dim ret as String*3 ret = Input("Input", "Limit 3", "", "String", "MaximumLength=3") Print ret |
|
readonly |
This is a read-only text-block. The DefaultExpr is evaluated and is used as the value. |
HelpText | String | ||
list | valuesExpr |
A Combo-box is displayed. The text portion of the combo-box is not editable. To make it Editable, use the property IsEditable=True. The DefaultExpr is evaluated and is used as the initial value. If the defaultvalue matches a value in the list, that value is selected. valuesExpr is needed to specify the choices: valuesExpr is assumed to contain a semi-colon (;) delimited list of choices. A semi-colon can be represented in the value by (;;). A quote can be represented in the value by (""). If the AllowMultiSelect property is True, then multiple choices can be made and the result is a ';' delimited string. |
AllowMultiSelect IsEditable CancelledValue HelpText ValidationPattern ValidationMessage AllowNoSelection |
String |
"george;ringo;paul;peter;""fred";;"" print Input("MapInfo", "_Select a Beatle: ", "", "list", "IsEditable=True;ValidationPattern=.+", "george;ringo;paul;peter")
print Input("MapInfo", "_Select a Beatle: ", "", "list", "IsEditable=False", "george;ringo;paul;peter") print Input("MapInfo", "_Select a Beatle: ", "george;ringo", "list", "AllowMultiSelect=True; ValidationPattern=.+; CancelledValue=None", "george;ringo;paul;peter;""fred""") |
values |
A Combo-box is displayed. The text portion of the combo-box is not editable. To make it editable, use the property IsEditable=True. The DefaultExpr is evaluated and is used as the initial value. If the defaultvalue matches a value in the list, that value is selected. valuesExpr is needed to specify the choices: valuesExpr it is assumed to be a MapBasic expression containing at least one table.column or column reference to an open table. It is evaluated against the rows in the table to get unique values until either 1000 unique values are found, the end of the table is reached, or two seconds have passed. |
CancelledValue HelpText AllowMultiSelect AllowNoSelection |
String |
UCASE$(usa.state_name) Open Table "C:\work\Data\USA\USA.TAB" Map From usa Dim val as string val = Input("MapInfo", "Search Value:", "", "values", "IsEditable=True;ValidationPattern=.*", "UCase$(usa.State_Name)") select * from usa where USA.State_Name like "%" + val + "%" Multiselect: Dim val as string val = Input("MapInfo", "Search Value:", "", "values", "AllowMultiSelect=True;ValidationPattern=.*", "UCase$(states.State_Name)") print val |
|
color |
A Color drop-down is displayed. The DefaultExpr is evaluated and is used as the initial value. The value is converted to an integer and is assumed to be in RGB format. If not specified, black is the default color. Note: The standard definitions file, MAPBASIC.DEF, includes Define statements for
several common colors (BLACK, WHITE, RED, GREEN, BLUE, CYAN,
MAGENTA, and YELLOW). If you want to specify a Red color, you
can simply use the identifier RED instead of calling RGB()
function.
|
CancelledValue HelpText |
Integer |
defaultExpr: RGB(255,0,0) defaultExpr: 255 |
|
window | :expr |
expr is a logical MapBasic expression that is evaluated for each open window. If it returns TRUE the window is included in the drop-down list. ScriptContext(1) is substituted with the ID of the window being evaluated. If no epxr is given, then all open windows are listed. If there is an error evaluating the expression, then the window is included. The DefaultExpr is evaluated and if it matches the ID of one of the listed windows, that window is pre-selected. The return value is the ID of the selected window or 0 if none. |
CancelledValue HelpText AllowNoSelection |
Integer |
WindowInfo(ScriptContext(2), 3)=1 WindowInfo(ScriptContext(2), WIN_INFO_TYPE)=1 Or WindowInfo(ScriptContext(2), WIN_INFO_TYPE)=2 Dim window as Integer window = Input("MapInfo", "Window:", "", "window") print window + ":" + WindowInfo(window, WIN_INFO_NAME)
window = Input("MapInfo", "Window:", frontwindow(), "window") print window + ":" + WindowInfo(window, WIN_INFO_NAME) Select a Map Window print Input("Choose Window", "_Select a Window:",frontwindow(), "", "window","windowinfo(ScriptContext(1), 3)=1") |
layer | :expr |
expr is a logical MapBasic expression that is evaluated for each layer in each open map. If it returns TRUE, the layer is included in the drop-down list. ScriptContext(1) is substituted with the ID of the map being evaluated. ScriptContext(4) is substituted with the ID of the layer being evaluated. If no expr is given, then all layers in the last used map are listed. If there is an error evaluating, the expression then the layer is included. The DefaultExpr is evaluated and if it matches the ID of one of the listed layers, that layer is pre-selected. The return value is the ID of the selected layer or 0 if no CancelledValue property is provided. Note: If multiple maps are included, then the return value is ambiguous. So it is expected
that the expression is used to pick only the layers from one
map.
|
CancelledValue HelpText AllowNoSelection |
Integer |
pick a selectable layer from the current map Dim layer as integer layer = Input("Choose Layer", "_Select a Layer:","1", "layer", "CancelledValue=-1", "ScriptContext(1)=FrontWindow() and LayerInfo(ScriptContext(1), ScriptContext(4), 3)=1") print layer pick a selectable Point layer from the current map layer = Input("Choose Layer", "_Select a Layer:","1", "layer", "CancelledValue=-1;HelpText=Selectable Point Layers", "ScriptContext(1)=FrontWindow() and LayerInfo(ScriptContext(1), ScriptContext(4), 3)=1 and TableInfo(LayerInfo(ScriptContext(1), ScriptContext(4), 1),60)=2") print layer |
coordsys |
Choose Projection dialog is displayed. if DefaultValueExpr is provided then, the Projection list will initialize to the matching projection member in the Choose Projection dialog. |
CancelledValue HelpText |
string | Print Input("Projection Picker", "Choose Projection","coordsys", "Coordsys Earth Projection 1, 104") | |
brush | Choose Brush dialog is displayed. |
CancelledValue HelpText |
brush |
dim b as brush b = Input("Brush", "Choose _Brush","", "brush") print b |
|
pen | Choose Pen dialog is displayed. |
CancelledValue HelpText |
pen |
dim p as pen p = Input("Pen", "Choose _Pen","", "pen") print p |
|
font | Choose Font dialog is displayed. |
CancelledValue HelpText |
font |
dim f as font f = MakeFont ("Arial Baltic",512,9,11599792,WHITE) f = Input("Font", "Choose _Font",f, "font") print f |
|
symbol | Choose Symbol dialog is displayed. |
CancelledValue HelpText |
symbol |
dim s as symbol s = Input("Font", "Choose _Font","Symbol (34, 16711680, 12)", "symbol") print s |