Solved

For Each ... In Collection fails

Posted on 1999-01-28
3
139 Views
Last Modified: 2010-05-03
I've written some ActiveX DLL:s that runs as Transaction Object in MTS. The problem is that the first time i create an object of one of my own classes and run a method that uses 'For Each ... In ...' it fails with error code 48 - "Error in loading DLL". If I at that point kill the mtx.exe process that transaction server has started and try again, it works just fine!

If I don't use For Each... in my method but instead use For x=1 to y.Count it works alright the first time around, but it isn't realistic to rewrite all of the code that way. Too many lines of code...

Have anybody seen this before, and what did you do to solve the problem?
0
Comment
Question by:anderse
3 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1471039
You have something like this?

Public Property Get NewEnum() As IUnknown
    Set NewEnum = myCollection.[_NewEnum]
End Property

' For NewEnum to work properly, its
'   procedure ID must be set to -4.  To see
'   this, select Procedure Attributes
'   from the Tools menu.  In the Name box,
'   select Item, then click the Advanced
'   button.  You can see that the Procedure
'   ID has been set to -4.  ("Hide this
'   member" is checked, also, so that the
'   NewEnum method is hidden in the Object
'   Browser.)

0
 
LVL 10

Accepted Solution

by:
caraf_g earned 160 total points
ID: 1471040
Alas, this is a known bug!

There seem to be some weird and wonderful workarounds for this, but the best thing to do is to forget about using For Each, and resort to using a counter

Dim lngCounter As Long

lngCounter = 1
Do While lngCounter <= YourCollection.Count
    Set SomeObjectVariable = YourCollection(lngCounter)
    'And process each individual object in your collection here.
    lngCounter = lngCounter + 1
Loop

As you can see, it is not a very big change and you'll avoid all your problems this way!
0
 

Author Comment

by:anderse
ID: 1471041
Is this a bug in VB or is it a bug in Transaction Server? (Or perhaps in IIS)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question