OK I understand now what you need. Unfortunatly VB natively doesn't offer this since even the Seek statement uses a Long to position the file pointer. So you have to turn to the API. You need to open the file using CreateFile in the same manner as you're already doing to get the file size. Next you need to call the SetFilePointer function. This function takes two Long values to simulate a 64-bit long integer to position the file pointer. However the low order Long is passed ByVal and for this to work you would need to pass an unsigned long to this argument, and as you know VB doesn't support unsigned long integers. So the solution would be to make several calls to SetFilePointer and move it (at the most) 2GB each time from the current position. You can then use the ReadFile function to read the number of bytes you need. So you should read this into a byte array instead of a string. You can then convert the byte array into a string using the StrConv function.VB Code:
Private Declare Function SetFilePointer Lib "kernel32.dll" ( _ ByVal hFile As Long, _ ByVal lDistanceToMove As Long, _ ByRef lpDistanceToMoveHigh As Long, _ ByVal dwMoveMethod As Long) As Long Private Declare Function ReadFile Lib "kernel32.dll" ( _ ByVal hFile As Long, _ ByRef lpBuffer As Any, _ ByVal nNumberOfBytesToRead As Long, _ ByRef lpNumberOfBytesRead As Long, _ ByRef lpOverlapped As Any) As Long 'constant values that can be used in the dwMoveMethod argument of SetFilePointer Private Const FILE_BEGIN As Long = 0 Private Const FILE_CURRENT As Long = 1 Private Const FILE_END As Long = 2 [b]'I have skipped the declaration of CreateFile and CloseHandle since you already have them [/b] Public Function GetDbl(strFileName As String, dblPos As Double) As String Dim hFile As Long, bArr() As Byte Dim nBytesRead As Long hFile = CreateFile(strFileName, GENERIC_READ, FILE_SHARE_READ, _ ByVal 0&, OPEN_EXISTING, ByVal 0&, ByVal 0&) Do While dblPos > &H7FFFFFFF '= 2147483647 Call SetFilePointer(hFile, &H7FFFFFFF, ByVal 0&, FILE_CURRENT) dblPos = dblPos - &H7FFFFFFF Loop If CLng(dblPos) Then Call SetFilePointer(hFile, CLng(dblPos), ByVal 0&, FILE_CURRENT) End If Redim bArr(3999) As Byte 'arrays are zero based so this is 4000 bytes Call ReadFile(hFile, bArr(0), 4000, nBytesRead, ByVal 0&) Call CloseHandle(hFile) GetDbl = StrConv(bArr, vbUnicode) End Function




Reply With Quote