Out of Memory Error VB6 when try to add an existing Class module - dll

I'm working on a project in VB6. I have to add a download functionality. It contains 1 form, 1 class module and 1 module (bas) files. When I add the existing module to my project, it is successful But when I try to add the class module or the frm file to the project, it says OUT OF MEMORY. I have been banging my head against this issue for quite some time now but couldn't find any solution.
I cannot post any code because it's a company project. All I can tell is that its a huge project with thousands of lines of code. The module I'm trying to add is used to download a file over HTTP, and it accesses the methods in Wininet.dll.
I don't know if the project has reached it maximum limit of lines of code, or whether it's an issue of variables.
I have heard that making a DLL can solve this issue, but we don't need that. Can anyone help?

I think I've faced something similar in the past, and after some digging and trying different things it turned out to be the number of variables / forms / controls that we had in the project. There is a limit to the number of unique variable, constant, and control names you can have in the project.
The way we proved it was to add the module that didn't quite break it, then add an empty module. In the empty module start adding variables until it breaks, it shouldn't take to long.
We cured it by going through the code and changing names of labels on forms to be control arrays, using constants for strings, and removing any code that was old an no longer required. Try to remove unused variables as well.
If it makes life easier you could try moving some of the code out to dll's.
Hope this helps.
Cast your eye over this, the sub sections might help:
VB6 Project Limitations

You know there are high level objects available that do in two or three lines what requires many in Wininet.
Try this way using xmlhttp. Edit the url's etc. If it seems to work comment out the if / end if to dump info even if seeming to work. It's vbscript but vbscript works in vb6.
On Error Resume Next
Set File = WScript.CreateObject("Microsoft.XMLHTTP")
File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
On Error Goto 0
Set BS = CreateObject("ADODB.Stream")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile "c:\users\test.txt", 2

Related

Why does this command sometimes throw array bounds exceptions when it contains no arrays

I have a process that loops through an array which is a list of PDF filenames, for each file it must write a template PDF which is stored in the same folder as the exe and copy this to a network share as "pdffilename"~001.pdf and then copy the data file from an S3 bucket to the network share as "pdffilename"~002.pdf. In some cases, the file won't exist but we would still need the separator and sometimes the code would just be writing multiple separators (~001) and no data files but when this happens I randomly get failures in writing the separator pdf.
This works fine when running on my laptop through VS but when I deploy the app up to our application server it fails when there are lots of missing files.
If sFile(0) <> "999-Envelopes" Then
Try
boxTriggerReqd = True
My.Computer.FileSystem.CopyFile("doc_sep.pdf", OutputFolder & "\" & Replace(oFileName, "~002.pdf", "~001.pdf"), True)
Log.writeline("Document Separator written:" & vbTab & OutputFolder & "\" & Replace(oFileName, "~002.pdf", "~001.pdf"))
Catch ex As Exception
Call EndTask(ex.Message, "Unable to transfer Document separator", 11)
End Try
Else
envTriggerReqd = True
End If
Try
dlResponse = s3client.GetObject(GetFile)
With dlResponse
.WriteResponseStreamToFile(OutputFolder & "\" & oFileName)
.Dispose()
End With
Log.WriteLine("Data file written:" & vbTab & vbTab & OutputFolder & "\" & oFileName)
Catch ex As Exception
results.WriteLine(sFile(1))
Call EndTask(ex.Message, targetFile, 12)
results.Flush()
End Try
The error log shows
****** S3 PULL ******
Index was outside the bounds of the array.
Unable to transfer Document separator
****** S3 PULL ******
Where it has called EndTask contains the "Unable to transfer Document separator" so it has happened in one of three commands
I'm assuming its the CopyFile command but there is no reference to an array in any of those three. Is it possibly a memory error on the server itself?

Download File and Extract Immediately - File is being used by another process

I'm looping through a list of zip files and downloading them from a WebClient. I'm trying to extract them immediately after they download, but getting an error that the file is being used by another process.
Error: The process cannot access the file 'c:\temp\test.zip' because it is being used by another process.
The only thing that I can think of is that maybe the file is still "in use" for a short time after being downloaded? DownloadFile does block ("This method blocks while downloading the resource." - http://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx), so I can't see it being an issue with the file still downloading.
Any ideas on a workaround?
Using client As New WebClient
oLog.Info("Downloading " & strFileServer & " to " & strFileLocal & "...")
If Not Directory.Exists(strPathLocal) Then Directory.CreateDirectory(strPathLocal)
client.DownloadFile(strFileServer, strFileLocal)
End Using
Using archive As ZipArchive = ZipFile.OpenRead(strFileLocal)
For Each entry As ZipArchiveEntry In archive.Entries
oLog.Info("Extracting " & entry.FullName & " to " & strPathLocal & "...")
entry.ExtractToFile(strFileLocal, True)
Next
End Using

Error 440 in Visual Basic Application

There is an old VB application running at one of my clients.
An exception is throws in this peice of code:
cn=GetIndexDatabaseConnectionString()
sSql="SELECT * FROM Arh_Naroc WHERE StNarocila = '" & isci & "'"
rs=CreateObject("ADODB.Recordset")
Call rs.Open(sSql,cn)
The exception happens in rs.Open() function. "Error number 440 occured."
This are SBL scripts for KOFAX engine and it's many years old.
The whole SW was transferred from old XP computer to Windows 7 and looks like there are problems everywhere.
Can some one help me determine what is the problem here. At least if I could get a proper error message back in msgbox would be most helpful.
EDIT:
This is the connection string function.
Function GetIndexDatabaseConnectionString
Dim objXmlDocument As Object
Dim objXmlGlobalSettingsFileParh As Object
Dim objXmlIndexDatabaseConnectionString As Object
Dim strGlobalSettingsFilePath As String
Dim strTemp As String
Const strSettingsFilePath = "C:\Data\LocalDocsDistibutingSystem\Settings.xml"
Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
objXmlDocument.Load strSettingsFilePath
Set objXmlGlobalSettingsFileParh = objXmlDocument.selectSingleNode("DocsDistributingSystem/GlobalSettingsFilePath")
strGlobalSettingsFilePath = objXmlGlobalSettingsFileParh.childNodes(0).Text
Set objXmlGlobalSettingsFileParh = Nothing
Set objXmlDocument = Nothing
Set objXmlDocument = CreateObject("MSXML2.DOMDocument")
objXmlDocument.Load strGlobalSettingsFilePath
Set objXmlIndexDatabaseConnectionString = objXmlDocument.selectSingleNode("DocsDistibutingSystem/AscentCapture/IndexDatabase/ConnectionString")
strTemp = objXmlIndexDatabaseConnectionString.childNodes(0).Text
Set objXmlIndexDatabaseConnectionString = Nothing
Set objXmlDocument = Nothing
GetIndexDatabaseConnectionString = strTemp
End Function
This is the relevant line from Settings.xml:
<ConnectionString> Provider=OraOLEDB.Oracle;Data Source=LINO2;User Id=****;Password=****;OLEDB.NET=True; </ConnectionString>
The real data is masked with *. The connection to Oracle appears to be ok. I created ODBC and linked server to sql using the provider and connection data. It works. It must be something missing installed on the computer for ADODB to work...
The connection appears to be working OK. There is no error when its initialized.
The error happens in Call rs.Open(sSql, cn). All i want is the detailed error message when the error happens...
Many thanks.
As it states on MS Knowledge Base
An error occurred while executing a method or getting or setting a
property of an object variable. The error was reported by the
application that created the object. Check the properties of the Err
object to determine the source and nature of the error. Also try using
the On Error Resume Next statement immediately before the accessing
statement, and then check for errors immediately following the
accessing statement.
So as they suggest check the Err object, in a similar fashion to:
If Err.Number <> 0 Then
Msg = "Error: " & Str(Err.Number) & ", generated by " _
& Err.Source & ControlChars.CrLf & Err.Description
MsgBox(Msg, MsgBoxStyle.Information, "Error")
End If
So this will bring back the error in a MsgBox, however you can just use Response.Write if you want it easier to copy & paste etc..
to get the error description you can do as follows :
Function GetIndexDatabaseConnectionString()
On Error GoTo Errorfound
'your
'function
'body
Exit Function
Errorfound:
With Err
MsgBox "Source: " & .Source & vbCrLf & "Desc: " & .Description, vbCritical, "Error " & CStr(.Number)
End With 'Err
End Function

Open Word Document From Dynamic Directory VB.Net

I have a program for which I have developed a user guide. I have placed this user guide within the project directory. I created a MenuStrip Item by which to open the user guide in Word on the user's machine. I was successfully able to do this with the following code:
Try
userGuide = MSWord.Documents.Open("C:Users\administrator\Documents\VisualStudio2010\Project3\UserGuide.doc")
MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal
MSWord.Visible = True
Catch ex As Exception
MsgBox("An error has prevented the document from opening. The document may not be available." & vbCrLf & vbCrLf & _
"Please try one of the following options:" & vbCrLf & _
"- Check to see if the document is already open" & vbCrLf & _
"- Restart the program")
End Try
The problem is, the path used to open the file will not exist on the users machine. This is a standalone system, so no file share can be created in which to place the document, therefore no common path can be coded.
Is there a way to code dynamic paths? Perhaps something like:
userGuide = MSWord.Documents.Open("%windir%\UserGuide.doc")
Thanks!
if the document will be stored relative to the install path of the application executable, then start with the path of the exe:
Dim path As String
path = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim docPath as String;
docPath = Path.Combine(path,"UserGuide.doc");

Debug a bad DLL calling convention

How do I debug a bad DLL calling convention error in MSAccess VBA code?
I made some changes to a function in a module and then got the error. How do a debug it to find the cause?
The error occurs on the Exit function statement of the function.
I fixed this problem by making a change in one of my class modules, executing a compilation from the Debug menu, and then undoing the change.
Background: In my case I've seen this in Excel without any external references. It happened, as with your problem, on an Exit Function call. Excel doesn't seem to have a /decompile option. I suspect that one of my class modules had mis-compiled for some reason, and Excel won't re-compile unless it thinks something has changed.
Have you checked your references and decompiled?
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"
"d:\My Documents\access\mayapp.mdb" /decompile
See also: http://www.granite.ab.ca/access/decompile.htm
VBScript Decompile
Check references in code
Dim ref As Reference
Dim sMsg As String
''Available since 2010
If BrokenReference Then
For Each ref In References
''Available since at least 2000
If ref.IsBroken Then
sMsg = sMsg & "Ref Name: " & ref.Name
'Also, if required
'sMsg = sMsg & vbCrLf & "Built In: " & ref.BuiltIn
'sMsg = sMsg & vbCrLf & "Full Path: " & ref.FullPath
'sMsg = sMsg & vbCrLf & "GUID: " & ref.Guid
'sMsg = sMsg & vbCrLf & "Kind: " & ref.Kind
'sMsg = sMsg & vbCrLf & "Major (version number): " & ref.Major
'sMsg = sMsg & vbCrLf & "Minor (version number): " & ref.Minor
sMsg = sMsg & vbCrLf & "=================================" & vbCrLf
End If
Next
MsgBox sMsg
End If
I experienced and worked around this error using the .NET library for WinSCP from MS Access VBA.
What happened was:
A function UploadSomething for connecting to an SFTP server and uploading a file worked fine.
Within the function UploadSomething changed the "resume support" option with this code: myTransferOptions.ResumeSupport.State = TransferResumeSupportState.TransferResumeSupportState_Off
After the change, the code worked as desired. However in the code that called UploadSomething, Error 49 was thrown after the function had finished.
The error happened both when stepping through the code using the debugger and when executing at once outside of the debugger. Recompiling the project didn't work for me.
What did work was this:
Remove the reference to the COM component
Add the reference to the COM component
Recompile
In Excel VBA, this can be caused by any of several problems:
A parameter or return-value type mismatch.
An object method (such as AutoFit) applied to an erroneous object
variation for which that method isn’t available.
A call to an external library function.
Broken library references
For resolutions to these causes, see my post at: Runtime Error 49, Bad DLL calling convention
I've just got this in Excel and wondered if anyone else have gotten it previously. My solution was to move around the references to my own DLL and click 'Compile <Project>'.
We've run into some problems with VBA when trying to call a DLL compiled in Intel Fortran. It turns out that you need to align the calling conventions back to a "C" context with the compiler flag calling convention: cfv
More info here on the Intel website
Another useful thread on the same problem: Intel Fortran DLL <-> C