Print, PrintLine Procedures

   
Print, PrintLine Procedures

Class

Microsoft.VisualBasic.FileSystem

Syntax

 Print(   filenumber   , [   outputlist   (  )]) PrintLine(   filenumber   , [   outputlist   (  )]) 
filenumber (required; Integer)

Any valid file number.

outputlist (optional; Parameter array)

A comma-separated list of expressions to output to a file.

outputlist can be either a scalar variable, a list of comma-delimited expressions, or a parameter array. Its comma-delimited expressions or parameter array can include the following:

Spc ( n ) (optional)

Insert n space characters before expression.

Tab ( n ) (optional)

Position the insertion point either at the next print zone (by omitting n ) or at column number ( n ).

expression (optional; any)

The data expression to output.

Description

Outputs formatted data to a disk file opened for Append or Output

Rules at a Glance

  • Print and PrintLine are identical, except that PrintLine advances to the next line after printing.

  • The Tab( n ) argument does not actually insert any tab characters ( Chr(9) ); instead, it fills the space from the end of the last expression to column n (or to the start of the next print zone) with space characters.

  • The Print procedure uses the locale settings of the current system to format dates, times, and numbers , using the correct separators.

  • outputlist can be either a comma-separated list of expressions or a parameter array.

Example

The following code shows how to use the Print procedure to write to a file using both a comma-separated list of arguments and a parameter array:

 Dim sInput As String Dim iFile As Integer = FreeFile(  ) Dim iNum As Integer Dim oOutput(1) As Object FileOpen(iFile, "C:\dataprex.txt", openmode.append) Do    sInput = InputBox("Enter name: ")    if sInput = "" Then Exit Do    Print(iFile, sInput)       iNum = Len(sInput)    sInput = InputBox("Enter street address: ")    oOutput(0) = spc(25 - iNum)    oOutput(1) = sInput    Print(iFile, oOutput)    iNum += Len(sInput)    sInput = InputBox("Enter city: ")    PrintLine(iFile, spc(40 - iNum), sInput) Loop While Not sInput = "" FileClose(iFile) 

Programming Tips and Gotchas

You may find that sequential data files written using the Print procedure are misinterpreted by the Input function. For heavily structured sequential data, you may get better results with the Write procedure, which ensures that all fields are correctly delimited.

VB.NET/VB 6 Differences

  • In VB 6, the Print statement requires a # symbol in front of filenumber . In VB.NET, this usage is not supported.

  • In VB 6, the final argument in outputlist , charpos , allows you to specify the starting character position of the next output. In VB.NET, however, this argument is not supported.

See Also

FileOpen Procedure

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net