Results 1 to 9 of 9

Thread: Is my input file too big for VB?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    8

    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!

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Is my input file too big for VB?

    With files over 2GBytes, you have to switch to API

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    8

    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?

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Is my input file too big for VB?

    These are the APIs I use:
    VB Code:
    1. 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
    2.  
    3. Private Type OVERLAPPED
    4.     Internal As Long
    5.     InternalHigh As Long
    6.     Offset As Long
    7.     OffsetHigh As Long
    8.     hEvent As Long
    9. End Type
    10.  
    11. 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
    12. 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
    13. 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
    14. 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
    15. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    16.  
    17. ' SetFilePointer, sets AND reads pointer position
    18. 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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    8

    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.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    8

    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.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Is my input file too big for VB?

    Quote 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)

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width