Read Method

 

Description

 

Reads a specified number of characters from a TextStream file and returns the resulting string.

 

PowerBASIC Syntax

 

METHOD Read ( _

BYVAL nCharacters AS LONG _

) AS STRING

 

Arguments

 

nCharacters

LONG. Number of characters you want to read from the file.

 

Remarks

 

After a file is initially opened and before anything is written, Line is equal to 1.

 

Example [PowerBASIC]

 

#INCLUDE "windows.inc"

#INCLUDE "scrrun.inc"

 

DIM fso AS IFileSystem

DIM pStm AS ITextStream

DIM curLine AS LONG

DIM strText AS STRING

 

' Create an instance of the FileSystemObject

fso = NEWCOM "Scripting.FileSystemObject"

' Open the file for reading

pStm = fso.OpenTextFile(UCODE$("C:\MyFolder\Test.txt"), %IOMode_ForReading, %FALSE, %FALSE)

' Read the file sequentially

WHILE ISFALSE pstm.AtEndOfStream

  ' Current line

  curLine = pStm.Line

  IF curLine = 3 THEN

     ' Skip the 3rd line

     pStm.SkipLine

     curLine = curLine + 1

  END IF

  ' Skip 10 characters

  pStm.Skip 10

  ' Current column

  curCol = pStm.Column

  ' Read 5 characters

  strText = pStm.Read(5)

  ' Skip the rest of the line

  pStm.SkipLine

  STDOUT "Line " & FORMAT$(curLine) & ", Column " & FORMAT$(curCol) & ": " & ACODE$(strText)

WEND

' Close the file

pstm.Close

 

Valid XHTML 1.0 Transitional