|
-
May 11th, 2005, 10:02 AM
#1
Thread Starter
New Member
Is my input file too big for VB?
I have a very big fixed length file to read into VB6 (record length 2201).
Each record is only terminated by a line feed and not cr/lf so line input does not work.
In binary mode it works until I reach byte 2,147,483,648 which I believe is the maximum length of a variable length string variable - and then I get "Error code 63: bad record number".
What other options are available to me to access this data? help!
-
May 11th, 2005, 10:10 AM
#2
Re: Is my input file too big for VB?
With files over 2GBytes, you have to switch to API
-
May 11th, 2005, 10:34 AM
#3
Thread Starter
New Member
Re: Is my input file too big for VB?
Thanks for the reply.
Excuse my ignorance but can anyone point me in the direction of what APIs I should be using?
-
May 11th, 2005, 10:40 AM
#4
Re: Is my input file too big for VB?
These are the APIs I use:
VB Code:
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Type OVERLAPPED
Internal As Long
InternalHigh As Long
Offset As Long
OffsetHigh As Long
hEvent As Long
End Type
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
Private Declare Function WriteFileEx Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpOverlapped As OVERLAPPED, ByVal lpCompletionRoutine As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Private Declare Function ReadFileEx Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpOverlapped As OVERLAPPED, ByVal lpCompletionRoutine As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
' SetFilePointer, sets AND reads pointer position
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
To figure out how to use them, post a question in the API forum
-
May 11th, 2005, 11:03 AM
#5
Thread Starter
New Member
Re: Is my input file too big for VB?
Okay, I will start a thread entitled 'Reading files > 2GB in VB using API' on the API forum.
-
May 11th, 2005, 11:13 AM
#6
Re: Is my input file too big for VB?
Have you tried using the FILESYSTEMOBJECT to read the file?
We have had good luck with that when recordlengths get too large for VB.
-
May 12th, 2005, 04:40 AM
#7
Thread Starter
New Member
Re: Is my input file too big for VB?
FileSystemObject works!
Although the MSDN help is patchy to say the least.
It was only because I read another post that I knew to include Microsoft Scripting Runtime as a reference, and the sample code for OpenTextFile has a bug in it (ForAppending=8 not 3).
I am using On Error to detect the end of file at present - but is there a 'proper' way similar to the EOF function when usin the Open statement? Again, the help is patchy on this.
-
May 12th, 2005, 11:02 AM
#8
Re: Is my input file too big for VB?
 Originally Posted by rodders
FileSystemObject works!
Although the MSDN help is patchy to say the least.
It was only because I read another post that I knew to include Microsoft Scripting Runtime as a reference, and the sample code for OpenTextFile has a bug in it (ForAppending=8 not 3).
I am using On Error to detect the end of file at present - but is there a 'proper' way similar to the EOF function when usin the Open statement? Again, the help is patchy on this.
You could try using LOF (Length of file)
-
May 12th, 2005, 11:18 AM
#9
Re: Is my input file too big for VB?
We use FSO/TSO like this...
Code:
Set tso = fso.OpenTextFile(gstrInput)
Do While Not tso.AtEndOfStream
s1 = tso.ReadLine
.
.
.
lngReadCnt = lngReadCnt + 1
Loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|