Solved

For Each ... In Collection fails

Posted on 1999-01-28
3
141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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