CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2012
    Posts
    1

    Angry Out of Memory - Reading a 80MB file into memory in VB6

    I'm getting a VB6 "Out of Memory" error when reading contents from a large file (80MB) into memory to be streamed to a web service using the Microsoft INet Control. The web service only accepts a single "POST" call from the VB6 application to process the entire contents of the file. Below is the code snippet that I am using. The line in red is where I get the "Out of Memory" error. It is happening with "TSO.Read(FileName.Size - 1)". Can anyone help me resolve this issue?

    Thanks

    -------------------------------------------

    Dim FSO As FileSystemObject
    Dim TSO As TextStream
    Dim FileName As File
    Dim strImportFile As String

    strImportFile = GetImportFileName() ' gets the import filename
    HttpRequestHeader = GetRequestHeader() ' gets the http request header (25 character string)

    If Trim(strImportFile) <> vbNullString Then
    Set FSO = New FileSystemObject
    Set FileName = FSO.GetFile(strImportFile)
    Set TSO = FileName.OpenAsTextStream(ForReading, TristateFalse)

    'stream the data from the file to a webservice using Microsoft INet Control

    m_Inet.Execute , "POST", TSO.Read(FileName.Size - 1), HttpRequestHeader

    TSO.Skip FileName.Size
    TSO.Close
    End If

    Set TSO = Nothing
    Set FSO = Nothing

    -------------------------------------------

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Out of Memory - Reading a 80MB file into memory in VB6

    Wait until TSO exists on your machine. Then compress it. Then upload it.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Out of Memory - Reading a 80MB file into memory in VB6

    I'd think you'd be better off reading the file in chunks, and feeding the data to your upload routine as the server takes it. Not sure if the inet control would be the most appropriate for that though.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Out of Memory - Reading a 80MB file into memory in VB6

    If the web service only accepts a single POST command, splitting up is not an option.
    I'd first see what is causing the problem:
    Split up the troublesome line into two seperate commands. First read the file into a string variable
    Code:
    Dim strInFile as String
    strInFile = TSO.Read(FileName.Size - 1)
    then try to send the string
    Code:
    m_Inet.Execute , "POST", strInFile, HttpRequestHeader
    See which one fails.

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Out of Memory - Reading a 80MB file into memory in VB6

    Quote Originally Posted by WoF View Post
    If the web service only accepts a single POST command, splitting up is not an option.
    While it is true that there'd only be a single POST command, there would be many packets of data for a file of the size in question.

    The Winsock control has a SendProgress event. I'd think this could be used to collect additional chucks of data from the file to be sent. I've not used the inet control, so I don't know if it offers something of this sort.

    The POST command includes the total length of the data being sent, so the server would be expecting more if only part of it were sent. It's been awhile since I had to deal with this, so I'd probably use a packet sniffer to see what handshaking goes on between client and server during an upload.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

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

Featured