Search Tools Links Login

Read Write

Posted: 2003-06-01
By: ArchiveBot
Viewed: 169

Filed Under:

Visual Basic 6

No attachments for this post


read a text file and convert it into an array

Original Author: Brent Luyet

Inputs

csv txt

Returns

array

API Declarations

micorosoft scripting runtime

Code


'Purpose:This class is used to read and create files text files
'Dependancies:must add Reference Microsoft Scripting Runtime
'Creation Date: ?
'Author: Brent Luyet
'Revision  Date  Revision By
'1.02    3/30/03 BJL
Public Function read(InFile As String, outArray() As String)
'Purpose:This function receives a filename and returns values in an array
'Creation Date:?
'Author: Brent Luyet
'Revision  Date  Revision By
'1.01    1/30/03 mst
Dim fso As New FileSystemObject   'must add Reference Microsoft Scripting Runtime
Dim fts As TextStream
Dim inString As String       'temp value to hold string read from file
Set fts = fso.OpenTextFile(InFile, ForReading, False) 'open infile for read only
inString = fts.ReadAll       'read entire file into inString
outArray = Split(inString, vbCrLf) 'split inString into outArray
'Clean up
fts.Close
Set fts = Nothing
Set fso = Nothing
End Function
Public Function WriteFile(ByVal OutFile As String, ByRef outArray() As String)
'Purpose:This function will create a file using the values passed in the value out array
'Creation Date: Date Class was created
'Author: Brent Lyute
'Revision  Date  Revision By
'1.01    1/30/03 mst
Dim fso As New FileSystemObject 'must add Reference Microsoft Scripting Runtime
Dim fts As TextStream
Dim OutString As String     'temp val for holding array before writing to file
OutString = Join(WriteOut, vbCrLf) 'join array to temp string outString
Set fts = fso.OpenTextFile(OutFile, ForWriting, True) 'Open OutFile for write, overwrite
fts.Write OutString ' Write temp string outString to OutFile
'Clean UP
fts.Close
Set fts = Nothing
Set fso = Nothing
End Function


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.