Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

For Each ... In Collection fails

Posted on 1999-01-28
3
Medium Priority
?
144 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 320 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…

886 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