Skip to content

INPUT()


从控制台或文件读取指定数量的字符

语法

vb
declare function Input ( n as integer ) as string
declare function Input ( n as integer, filenum as integer ) as string

用法

result = Input[$]( n [, [#]filenum ] )

参数

n

要读取的字节数。

filenum

绑定文件或设备的文件号。

返回值

返回读取字符的 String

说明

从控制台或由 filenum 指定的绑定文件/设备读取指定数量的字符。

第一种版本等待并从键盘缓冲区读取 n 个字符。不读取扩展键。字符不会回显到屏幕。

第二种版本等待并从文件或设备读取 n 个字符。文件位置会更新。

注意:使用 Input() 自然适合 Input 访问文件模式,但在 Binary/Random 访问文件模式中也允许使用,但对 n 的值有一些限制(对于 random 模式,n 必须等于 OPEN 语句中的 LEN 子句(或隐式值)设置的记录长度)。

示例

start GeSHi

vb
Print "Select a color by number"
Print "1. blue"
Print "2. red"
Print "3. green"
Dim choice As String
Do
   choice = Input(1)
Loop Until choice >= "1" And choice <= "3"

end GeSHi

方言差异

  • -lang qb 方言中必须使用字符串类型后缀 "$"。
  • -lang fblite 方言中字符串类型后缀 "$" 是可选的。
  • -lang fb 方言中字符串类型后缀 "$" 被忽略,仅在使用 -w suffix 编译选项(或 -w pedantic 编译选项)时发出警告。

与 QB 的差异

另请参阅

  • Winput()
  • Getkey
  • Inkey

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系