VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Read Write

by Brent Luyet (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

read a text file and convert it into an array

Inputs
csv txt
Code Returns
array
API Declarations
micorosoft scripting runtime

Rate Read Write


'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

Download this snippet    Add to My Saved Code

Read Write Comments

No comments have been posted about Read Write. Why not be the first to post a comment about Read Write.

Post your comment

Subject:
Message:
0/1000 characters