Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Plant SCADA

Print #

  • Last UpdatedJul 18, 2023
  • 5 minute read

Print # statement reads data from OutputList and writes that data to a sequential file.

The Print # statement has two parameters FileNum and OutputList. The required FileNum argument is the associated file number used in the Open statement when the file was opened. The required OutputList argument is a delimited list of expressions whose values are written to the file.

Note: The number sign hash character ( # ) preceding FileNumis not optional. This character indicates disk file access with the file referenced by the system file number that follows it. Do not confuse Print # which prints to disk, with Print which displays data on the screen.

Data written with Print # is usually read from a file with Line Input # or Input.

Note: If you want to read the data from a file using the Input # statement, use the Write # statement instead of the Print # statement to write the data to the file. Using Write #properly delimits each separate data field, so it can be read back in using Input #. Using Write # also formats the data in a manner that will allow correct read operations in most locales.

If you omit expressionlist, the Print # statement prints a blank line in the file, but you must include the comma. Because Print # writes an image of the data to the file, you must delimit the data so it is printed correctly. If you use commas as delimiters, Print # also writes the blanks between print fields to the file.

The Print # statement usually writes Variant data to a file the same way it writes any other data type. However, there are some exceptions:

If the data being written is a Variant of VarType 0 (Empty), Print # writes nothing to the file for that data item.

If the data being written is a Variant of VarType 1 (Null), Print # writes the literal #NULL# to the file.

If the data being written is a Variant of VarType 7 (Date), Print # writes the date to the file using the Short Date format defined in the WIN.INI file. When either the date or the time component is missing or zero, Print # writes only the part provided to the file.

Syntax

Print #FileNum, OutputList

FileNum:

An Integer or numeric expression representing any valid number in the range 1 to 511 inclusive, which is referenced by the file system to be associated with an open file.

OutputList:

One or more formatted numeric and/or string expressions to be written to the file using the following syntax:

[ {Spc( s ) | Tab [( n ) ] } ] [expression] [charpos]

Where:

[ ] square brackets are used for illustrative purposes to indicate in the code that the arguments they enclose are optionally used in the OutputList. Do not use the square brackets themselves in your code.

{ } curly braces are required to encompass and delineate the arguments they enclose, and to separate their contents from the other arguments in the OutputList.

( | ) vertical line are used for illustrative purposes to indicate in the code that either side of the line is an alternative argument. You can use the argument provided on one of the line or the other, but not both arguments at the same time within the same set of curly braces. Do not include the vertical line in your code.

{Spc(s)} argument is optionally used to insert 's' number of space characters in the output file at the position of the argument in the OutputList. The Spc argument must be enclosed by curly braces to delineate it from an expression. The Spc argument can be repeated any number of times to insert spaces in the file between expressions. The Spc argument is mutually exclusive with the Tab argument when used within the same set of curly braces.

{Tab(n)} argument is optionally used to position the insertion point to an absolute column number in the output file at the position of the argument in the OutputList, where 'n' is the column number. Use Tabwith no argument to position the insertion point at the beginning of the next print zone. The Tab argument must be enclosed by curly braces to delineate it from an expression. The Tab argument can be repeated any number of times to insert tabs in the file between expressions. The Tab argument is mutually exclusive with the Spc argument when used within the same set of curly braces.

expression argument represents a valid numeric or string expression to output to the file. The expression argument can be repeated any number of times.

charpos is the character that determines the position of the next character in the output. A semicolon means the next character is printed immediately after the last character; a comma means the next character is printed at the start of the next print zone. Print zones begin every 14 columns. If neither character is specified, the next character is printed on the next line.

Return Value

Input # statement returns data record by record from a file opened in Input or Binary mode. Data items in a file must appear in the same order as the variables in VarList and match variables of the same data type. If a variable is numeric and the data is not numeric, a value of zero is assigned to the variable.

Get # | GetAttr | Input | Line Input # | Put # | Write #

Example

The following example writes data to a test file.

Dim I, FNum, FName ' Declare variables.

For I = 1 To 3

FNum = FreeFile ' Determine next file number.

FName = "TEST" & FNum

Open FName For Output As FNum ' Open file.

Print #1, "This is test #" & I ' Write string to file.

Print #1, "Here is another "; "line"; I

Next I

Close ' Close all files.

The following example writes data to a test file and reads it
back.

Dim FileData, Msg, NL ' Declare variables.

NL = Chr(10) ' Define newline.

Open "TESTFILE" For Output As #1 ' Open to write file.

Print #1, "This is a test of the Print # statement."

Print #1, ' Print blank line to file.

Print #1, "Zone 1", "Zone 2" ' Print in two print zones.

Print #1, "With no space between" ; "." ' Print two strings
together.

Close #1

Open "TESTFILE" for Input As #2 ' Open to read file.

Do While Not EOF(2)

Line Input #2, FileData ' Read a line of data.

Msg = Msg & FileData & NL ' Construct message.

MsgBox Msg

Loop

Close #2 ' Close all open files.

Kill "TESTFILE" ' Remove file from disk.

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in