Skip to main content Link Search Menu Expand Document (external link) Copy Copied

CSVTextStream

Easy-to-use class module developed to enable I/O operations over “big” text files, at high speed, from VBA. The module hasn’t reference to any external API library and has the ability to read and write UTF-8 encoded files.


Members

Item Type Description
atEndOfStream Property Gets the overall state of the pointer on the text stream. Returns True if the file pointer is at the end of a file, and False otherwise.
bufferLength Property Gets the number of string characters in the buffer.
bufferSize Property Gets or sets the buffer size, in MB, for text stream operations. Allows the user to specify how much data is read at a time. By default, the bufferSize property is set to 0.5 MB. For files containing very long lines, the size is modified to be enough to contain at least one line.
bufferString Property Gets the text data stored in the buffer. If one or both of the unifiedLFOutput and utf8EncodedFile properties are set to True, the string is operated on before returning data.
CloseStream Method Closes the current text file stream. After close the current stream, user will lose the connection to CSV file.
endStreamOnLineBreak Property Allows to end buffer just after the first, from right to left, line break character.
isOpenStream Property Gets the stream status over the current CSV file.
lineBreak Property Gets the last line break character read.
linebreakMatchingBehavior Property Gets or sets the behavior of line break matching in subsequent text stream operations. Allows the user to specify how line breaks are searched for to end the current buffer in vbCrLf, vbCr or vbLf as specified in the endStreamOnLineBreak property. By default, the property property is set to EndLineMatchingBehavior.Bidirectional, this option ensures the handling of files with long lines that cannot be contained in a string of specified size as in the bufferSize property. Setting the linebreakMatchingBehavior property to EndLineMatchingBehavior.OnlyBackwardSense may cause unexpected behavior when the stream is requested to end at a line break and the current text stream contains a portion of a long line that cannot be stored in the specified buffer size.
OpenStream Method Opens a stream over a CSV file. Before stream over a text file, user must open a stream pointing to that file. If the text file doesn’t exist, it will be created and then a stream is opened.
pointerPosition Property Gets the overall pointer position over the current text file.
ReadText Method Reads a number of characters from the stream file and saves the result to the bufferString of current instance. Each call to this method will read a set of characters until the buffer size is reached. If the EndStreamOnLineBreak property is set to True, the stream will be cut off at the first occurrence of a line break (CRLF, CR or LF) in the reverse left (right-to-left) direction or some extra data will be appended to it until a line break character is encountered in the forward direction. The ReadText method will continue to read data until the pointer exceeds the length of the current text file.
RestartPointer Method Moves the pointer to the initial position of the CSV file and clears the buffer. The user must open a stream before attempting to restart the reader.
SeekPointer Method Moves the pointer, over the target file, to the specified position. The next I/O operation will start in the position specified with the SeekPointer method.
streamLength Property Gets the current opened file’s size, in Bytes.
unifiedLFOutput Property Determines whether the buffer string is returned using only the vbLf character as end of lines.
UTF8Decode Method Decodes an UTF-8 string. This method makes it possible to read and write CSV files in foreign languages, share mathematical symbols through CSV files and much more.
utf8EncodedFile Property Determines whether the buffer string is decoded from UTF-8 encoding.
WriteBlankLines Method Inserts a specified number of blank lines into the current opened CSV file.
WriteText Method Writes the given string to the current opened CSV file. User must open a stream before try to write data to file.

Back to API overview