-
I need to know the quickest way to read many (up to 3,000) smaller files (usually below 500 K) into memory. Right now I am reading them in one line at a time. I tried using input for the len of the file, but that did not help.
Is there some way to make vb not do this sequentially - could I write something in C++ and call it from vb . . . anything please
-
There are many ways indeed to acomplish what you want to do. A COM object written in C++, would indeed be a very good way to do it. All you then need to do is to refernce the dll from your VB project and code away.
Other than that, i would have said the Input function, and the Get function. I usually find that the Get function is quicker on smaller files, while the Input function is quicker on larger files.
Code:
Private Sub inputMethod(strFile As String)
Dim strText As String
Open strFile For Input As #1
'get the whole file.
strText = Input(LOF(1), #1)
Close #1
End Sub
Private Sub getMethod(strFile As String)
Dim bTemp As String
Dim strText As String
Open strFile For Binary As #1
'redim the byte array to the size of the file
ReDim bTemp(LOF(1) - 1) As Byte
'get the file in binary
Get #1, , bTemp
Close #1
'convert the byte array to a string
strText = StrConv(bTemp, vbUnicode)
End Sub
-
Personally I would use the FileSystemObject. It allows you to open the file as a single string in one operation.