The following function enable you to read in, for instance a text file, into memory to use within your routines.
'--------------------------------------------------------------------------------------- ' Procedure : ReadFile ' Author : CARDA Consultants Inc. ' Website : http://www.cardaconsultants.com ' Purpose : Faster way to read text file all in RAM rather than line by line ' Copyright : The following may be altered and reused as you wish so long as the ' copyright notice is left unchanged (including Author, Website and ' Copyright). It may not be sold/resold or reposted on other sites (links ' back to this site are allowed). ' Input Variables: ' ~~~~~~~~~~~~~~~~ ' strFile - name of the file that is to be read ' ' Usage Example: ' ~~~~~~~~~~~~~~~~ ' MyTxt = ReadText("c:\tmp\test.txt") ' MyTxt = ReadText("c:\tmp\test.sql") ' MyTxt = ReadText("c:\tmp\test.csv") '--------------------------------------------------------------------------------------- Function ReadFile(ByVal strFile As String) As String On Error GoTo Error_Handler Dim FileNumber As Integer Dim sFile As String 'Variable contain file content 'If FileExist(strFile) = False Then ' MsgBox "The specified file could not be found!" ' Exit Function 'End If FileNumber = FreeFile Open strFile For Binary Access Read As FileNumber sFile = Space(LOF(FileNumber)) Get #FileNumber, , sFile Close FileNumber ReadFile = sFile Error_Handler_Exit: On Error Resume Next Exit Function Error_Handler: MsgBox "The following error has occured." & vbCrLf & vbCrLf & _ "Error Number: " & Err.Number & vbCrLf & _ "Error Source: ReadFile" & vbCrLf & _ "Error Description: " & Err.Description, _ vbCritical, "An Error has Occured!" Resume Error_Handler_Exit End Function
c


