Input # Statement

Allows string or numeric data to be received from a file, communications port, or database and stored in one or more variables.

Syntax
Input #portNumber, varName [ , varName, varName,... ]

Parameters

portNumber
ID number representing a file, communications port, database, or device. File number can be specified in ROpen, WOpen, and AOpen statements. Communication port number can be specified in OpenCom (RS-232C) or OpenNet (TCP/IP) statements. Database number can be specified in OpenDB statement.
Device ID integers are as follows.

  • 21 RC+
  • 24 TP (TP1 only)
  • 20 TP3
varName
Specify the variable name to receive the data.

Description
The Input # instruction receives numeric or string data from the device specified by handle, and assigns the data to the variable(s).

Notes


  • About the Controllers to use

    For T/VT series, an error will occur at operation when RS-232C port of the Controller is specified.

  • Rules for Numeric Input

    When inputting numeric values and non-numeric data is found in the input other than the delimiter (comma), the Input instruction discards the non-numeric data and all data following that non-numeric data.

  • Rules for String Input

    When inputting strings, numeric and alpha characters are permitted as data.

  • Maximum data length

    This command can handle up to 256 bytes. However, the target is the database, it can handle up to 4096 bytes. If the target is the communication port (TCP/IP), it can handle up to 1024 bytes.

  • Other Rules for the Input # Instruction

    • When more than one variable is specified in the instruction, the numeric data input intended for each variable has to be separated by a comma (",") character or blank (“ ”).

    • When more than one string variable or both of numeric variable and string variable is specified, the numeric data has to be separated by a comma (“,”) character or blank (“ “).

    • The input data type must match the variable type.

    • The following programs are examples to exchange the string variable and numeric variable between the controllers using a communication port.

    • Sending end (Either pattern is OK.)

      Print #PortNum, "$Status,", InData, OutData
      Print #PortNum, "$Status", ",",InData, OutData
      
    • Receiving end

      Input #PortNum, Response$, InData, OutData
      

Potential Error

  • Number of variables and input data differ

    When the number of the variables specified in the instruction is different from the number of numeric data received from the device, an Error 2505 will occur.

See Also
Input, Line Input, Line Input #, Print #, Read, ReadBin

Input # Statement Example
This function shows some simple Input # statement examples.

Function GetData
    Integer A
    String B$

    OpenCom #1
    Print #1, "Send"
    Input #1, A   'Get a numeric value from Port#1
    Input #1, B$  'Get a string from Port#1
    CloseCom #1
Fend