Solved

For Each ... In Collection fails

Posted on 1999-01-28
3
136 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now