Solved

For Each ... In Collection fails

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

919 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

15 Experts available now in Live!

Get 1:1 Help Now