Solved

Run Time Error 91

Posted on 2001-06-26
17
258 Views
Last Modified: 2010-05-02
I have an application with 2 projects: an exe and an ActiveX DLL project.
The DLL contains some classes.
These 2 projects are in 2 different directories.
I grouped these 2 projects (in group1.vbg) and I developed an application that run very well.
But when I generate an exe file from the exe project and a dll file from the ActiveX project the things don?t work.
I have registered the dll with regsvr32 and I have referenced this dll in the exe project.
When I run the program I get Run Time Error 91 (Object variable or with block variable not set), when the program tries to instantiate a class from dll for the first time.
Why did I get this error? Is it something like I haven?t set a path to the other directory with dll files?
MSDN help tells that the error occurs when it isn?t a reference to BOT project (ActiveX DLL project). But I have the reference to BOT project.
0
Comment
Question by:redundguy
17 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6226948
Runtime 91 is the Object Variable or With Block not set!

Your ActiveX Dll project should be set to Binary Compatible in order to function correctly when compiled...
You can meanwhile inverse the order: first compile the DLL and then the EXE (you should not need to register this DLL, as during the MAKE it is registered automatically by VB).

Anyway, you might try to Add both projects into a project Group (See File->Add Project), which should simplify things for the debugging...

Cheers
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6226955
You probably referenced the dll in your project group. So I suggest you open the EXE project only, set the new reference to the compiled dll and then recompile the executable.

regards,
CJ
0
 
LVL 1

Author Comment

by:redundguy
ID: 6227087
I have set DLL project to Binary Compatible and I get the same error.
When I use Group of projects my reference is set to the vbp file of ActiveX project.
When I open only EXE project my reference is set to dll file of the ActiveX project.
When I run the group of 2 projects all run OK.
When I run EXE project I get error 91.

I am not very interested in what I have done wrong; but I?m more interested in what have I do to create and run the exe and dll files.

Thanks
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6227206
When you het the errors message, which module causes the error is it the EXE or the DLL?

Also, show us the code where you are creating a reference to your object within the DLL.

Does it look something like this:

Dim MyObj

Set MyObj=CreateObject("MyProject.MyClassName")

?





0
 
LVL 18

Expert Comment

by:deighton
ID: 6227553
are you using late or early binding?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6229566
>>When I open only EXE project my reference is set to dll file of the ActiveX project

this leads me to believe he is using early binding (otherwise, supplying the reference would be pointless)

it sounds like a versioning problem.  try and unregister the component using regsvr32 /u [componentpath]
you really dont need to set binary compatibility until you know your component is pretty well developed, and doing so wont cause possible future requirements to break compatibility.
as mentioned previously, simply choosing File -> Make dll will register your component (on your machine).  in the exe that is referencing the component, open up project -> references, and deselect the component and click OK.  then, open up project -> references again and select your newly compiled component.

in addition, in code, ensure you have actually created an instance of your component before using it.  e.g.,

'you didnt do something like this
Dim obj As MyComponent.ClassName
Call obj.SomeMethod

ensure it is declared using the New keyword, or preferrably, setting the variable to a new instance of your component when it is needed.
0
 
LVL 1

Author Comment

by:redundguy
ID: 6230027
Thanks, but I think that Visual Basic cheated me. I tried to trace the DLL program with MsgBoxes included in DLL program, and I got an error in DLL program. The error is related to a connection object.

In fact it is a small story. I got an error related to connection object. Then I insert a code line (MsgBox oConnection,,?connection string?) before the line where I got the error. When I run the program in IDE I see the connection string and then the program run OK. When I run the EXE program I get this 91 runtime error.

Now I have to discover the error cause. It is something related to using public variable of type connection in the Modules section of ActiveX project. One object (class) of the DLL project sets the public variable (connection) and other objects (classes) use this connection. I get the error in the first object code which try to use the connection.
I repeat that I don?t get the error when I run the program in IDE, only when I run the EXE and DLL programs.

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6230101
>>I repeat that I don?t get the error when I run the program in IDE, only when I run the EXE and DLL programs

this can happen if your exe is not referencing the most current version of your component.  try de-referencing and then re-referencing as i suggested above.  if that does not work, post some code (or check what differences there are in code between your test app and actual exe)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:redundguy
ID: 6233950
I have to reformulate the issue: Problem with Public variable in ActiveX DLL project

I have an application with 2 projects: an exe and an ActiveX DLL project.
The DLL contains some classes and is  ?Single threaded apartment?.
The module section of DLL contains a public variable vp1 (integer)
The EXE program instantiates an object in DLL program and call a method that set the vp1 variable.
Then the EXE program instantiate another object in DLL  program and call a method that show the value of vp1.
But I don?t see the value already set  with the first object: vp1 variable isn?t public for all classes from DLL project.
Why ?
0
 
LVL 1

Author Comment

by:redundguy
ID: 6233985
I mention that these things happen when I run the exe file of the EXE project. When I run the Project from IDE, the second class shows the right value for the public variable.
0
 
LVL 1

Author Comment

by:redundguy
ID: 6234188
I have to add some words about EXE project:
It is a form. In the load event I instantiate an object in DLL program and call a method that set the vp1 variable.
In the Click event of a button I instantiate another object in DLL  program and call a method that show the value of vp1. I cannot get the value allready set.
If I instantiate both objects in the same procedure (in load event of the form) I can get the correct value for vp1 when I call the method of the second object.


0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6234749
please clarify what you mean when you say "object".  do you mean you are creating a new instance of the same class?  a different class in the DLL?  how many classes are in your DLL?  just give us the basic outline of your component, e.g.,

DLLName
   -Class1
   -Class2
   -Class3
   -Module1


and then show the variable declarations and code you use to create each class and how you are calling the methods.
0
 
LVL 1

Author Comment

by:redundguy
ID: 6236937
My application is quite complex but I actually reduced my problem at this code:

DLLname project contains:
-in Modules section:
public vp1 as integer
-in Class Modules section I have:
Class1, that have a method (method1) that sets vp1 variable
Class2 that have a method (method2) that gets vp1 variable and shows it.
In fact I want to share data between classes of the same DLL.

The exe program is a form with 2 buttons.

In the click event of the first button I have:

Dim oClass1 as DLLname.Class1
Set oClass1= New DLLname.Class1
OClass1.method1

In the click event of the second button I have:

Dim oClass2 as DLLname.Class2
Set oClass2= New DLLname.Class2
Oclass2.method2

If I run my exe file application, method2 doesn?t show the value already set with method1.

If I run the application from the IDE all is OK. (But my application will be an exe file).

(Another thing is: If I instantiate and run method of both classes in the same event procedure, the method2 show the right value. But I really need 2 buttons)

The problem is that I cannot share data between classes. A solution is to keep the common data in the EXE project and to send this data as a parameter to the second class method (method2). I'm going to do that if I cannot use a public variable in the DLL.

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6238490
what is your threading model?  it should be set to apartment threading if you wish to share global data in this way.
0
 
LVL 1

Author Comment

by:redundguy
ID: 6244159
I have set to apartment threading but it doesn't work.

I'm going to use the solution with keeping common data in the client exe and pass them as parameter to dll methods.

Maybe there are a direct solution to my problem but I realy have no time now to try.

Thanks to all of you




0
 
LVL 1

Author Comment

by:redundguy
ID: 6248393
I have got a brilliant answer from Jim McNamara,
 on vb-world Q & A forum:

In general, you are trying to violate basic COM rules -
encapsulation in this case. Don't do it, not because of purist reasons, but because it won't work reliably as already you see, I'm not going into why it won't work. Just don't do it.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 77 total points
ID: 7139826
Hi redundguy,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Refund points and save as a 0-pt PAQ.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 …
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 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…
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now