Home |
Search |
Today's Posts |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
OK, I include the missing dependencies, so you can test.
The reason I use text files is that people that use my software sometimes have no Access. The other thing is that it surprisingly appears just as fast. If you can convince me that Access is faster I might have another look at using that. Function OpenTextFileToArray(ByVal txtFile As String, _ ByRef arr As Variant, _ ByVal LBRow As Long, _ ByVal UBRow As Long, _ ByVal LBCol As Long, _ ByVal UBCol As Long, _ Optional ByVal bSkipFields As Boolean = False) As Variant Dim hFile As Long Dim r As Long Dim c As Long Dim varWaste hFile = FreeFile Open txtFile For Input As #hFile On Error Resume Next If bSkipFields = False Then For r = LBRow To UBRow For c = LBCol To UBCol Input #hFile, arr(r, c) Next Next Else For c = LBCol To UBCol Input #hFile, varWaste Next For r = LBRow To UBRow For c = LBCol To UBCol Input #hFile, arr(r, c) Next Next End If Close #hFile OpenTextFileToArray = arr End Function Sub SaveArrayToText2(ByVal txtFile As String, _ ByRef arr As Variant, _ Optional ByVal LBRow As Long = -1, _ Optional ByVal UBRow As Long = -1, _ Optional ByVal LBCol As Long = -1, _ Optional ByVal UBCol As Long = -1, _ Optional ByRef fieldArr As Variant) 'this one organises the text file like 'a table by inserting the right line breaks '------------------------------------------ Dim r As Long Dim c As Long Dim hFile As Long If LBRow = -1 Then LBRow = LBound(arr, 1) End If If UBRow = -1 Then UBRow = UBound(arr, 1) End If If LBCol = -1 Then LBCol = LBound(arr, 2) End If If UBCol = -1 Then UBCol = UBound(arr, 2) End If hFile = FreeFile Open txtFile For Output As hFile If IsMissing(fieldArr) Then For r = LBRow To UBRow For c = LBCol To UBCol If c = UBCol Then Write #hFile, arr(r, c) Else Write #hFile, arr(r, c); End If Next Next Else For c = LBCol To UBCol If c = UBCol Then Write #hFile, fieldArr(c) Else Write #hFile, fieldArr(c); End If Next For r = LBRow To UBRow For c = LBCol To UBCol If c = UBCol Then Write #hFile, arr(r, c) Else Write #hFile, arr(r, c); End If Next Next End If Close #hFile End Sub Sub InsertLineAtBeginningTexFile(ByVal strFile As String, ByVal strLine As String) Dim FFile As Integer Dim FileContents As String Dim NewString As String FFile = FreeFile Open strFile For Binary As #FFile FileContents = Space(FileLen(strFile)) Get #FFile, , FileContents Close #FFile NewString = strLine & vbCrLf FileContents = NewString & FileContents Open strFile For Binary As #FFile Put #FFile, , FileContents Close #FFile End Sub Function GetFieldsFromText(ByVal strFile As String, ByVal lCols As Long) As String Dim hFile As Long Dim strTemp As String Dim strResult As String Dim c As Long hFile = FreeFile Open strFile For Input As #hFile On Error Resume Next For c = 1 To lCols Input #hFile, strTemp If c = 1 Then strResult = strTemp Else strResult = strResult & ", " & strTemp End If Next Close #hFile GetFieldsFromText = strResult End Function RBS "onedaywhen" wrote in message oups.com... RB Smissaert wrote: You could try loading your data into an ADO recordset and sorting it there. Google for "disconnected recordset" and ADO Thanks, but I have tried that already and it turned out to be about twice as slow. To be fair, you are not doing as Tim suggested in your code, which has too many missing dependencies (e.g. sub procedure SaveArrayToText2) to test <g. Rather than fabricating a recordset, your code appears to fabricate a text file. FWIW I don't think your recordset ever gets opened/populated because the SELECT..INTO..FROM syntax does not return a rowset. BTW do you have a business requirement to use text files as databases? Fabricating an .mdb file would yield better performance but I still have your PATIENT.txt and ENTRY.txt files from way back when to create an example JOIN between text files. Jamie. -- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Large Arrays | Excel Discussion (Misc queries) | |||
Fastest way to select large range (e.g. B3:F1002)? | Excel Discussion (Misc queries) | |||
Sort a large file then sum like values... | Excel Discussion (Misc queries) | |||
How to sort/update large excel db | Excel Discussion (Misc queries) | |||
Need FASTEST way to get data from a large closed Excel File | Excel Programming |