目录

# Print# Statement

Outputs the specified strings or numeric expressions to the screen or to a sequential file.

Use Put# statement to write data to a binary or a random file. Use Write# statement to write data to a sequential text file with delimiting characters.

### 语法:

    Print [#filenum,] expression1[{;|,} [Spc(number As Integer);] [Tab(pos As Integer);] [expression2[...]]

### 参数:

filenum: Any numeric expression that contains the file number that was set by the Open statement for the respective file.

expression: Any numeric or string expression to be printed. Multiple expressions can be separated by a semicolon. If separated by a comma, the expressions are indented to the next tab stop. The tab stops cannot be adjusted.

number: Number of spaces to be inserted by the Spc function.

pos: Spaces are inserted until the specified position.

如果最后一个要打印的表达式后面出现分号或逗号，LibreOffice Basic 将把该文字存储在一个内部缓冲区中并继续执行程序，但不执行打印。当遇到结尾处不含分号或逗号的另一个打印语句时，将一并打印所有需要打印的文字。

打印的正数表达式前面带有一个空格，而打印出的负数表达式前面带有一个减号。对于超出了浮点数取值范围的数字表达式，则以指数表示法打印。

如果要打印的数字表达式超出了一定的长度，将会自动换行。

您可以在自变量之间插入「Tab」函数 (用分号括起)，使输出缩进到指定的位置；或者使用「Spc」函数插入指定的空格数。

### 示例:

    Sub ExamplePrint
        Print "ABC"
        Print "ABC","123"
        i = FreeFile()
        Open "C:\Users\ThisUser\Temp.txt" For Output As i
        Print #i, "ABC"
        Close #i
    End Sub

    Sub ExamplePrint
        Print "ABC"
        Print "ABC","123"
        i = FreeFile()
        Open "~/temp.txt" For Output As i
        Print #i, "ABC"
        Close #i
    End Sub

相关主题

Close Statement

Put# Statement

Open Statement

Write# Statement