Using forms in DLL classes

SimDuck

Newcomer
Joined
Oct 25, 2004
Messages
21
Hi, I'm trying to use a dll to hold forms & code and instantiate them from an exe.

I can successfully do it when there is only one form in the dll. The problem I am having is when there are multiple forms in the one dll.

I load the dll to form 1. The user clicks a button and the code is supposed to open up form2 and execute some code. The error I am getting is:

"An unhandled exception of type 'System.NullReferenceException' occurred in add transactions.dll

Additional information: Object reference not set to an instance of an object
."

When this dll is built as an exe, it loads up on a module that has the "Sub Main" module in it and all forms work properly in an exe.

My question is, how do I have forms successfully interacting with each other under a dll environment? Or, Can I get the loading exe to call the "Sub Main" module first in the dll?

Your help is appreciated.

Thank you
 
@ PlausiblyDamp
I have form 1 (Add_Transaction) and form 2 (Insert_Line)

I have tried to declare form 2 as new frmInsertLine.

form 1 is the initial form loade up from the dll. In this form, the user selects a button and some code plus this one is executed. When the code in form 1 gets to this code, I get the afore mentioned error.

intX = frmInsertLine.Variable_Hold("0", "no", "Add") - 1

When I Break the error and hover my mouse over frmInsertLine, it says that frmInsertLine = Nothing. If I understand this correctly, it means that I haven't instantiated an instance of form 2 yet.

I am wondering how I get form 1 to know what form 2 is & vice versa. I wan't to instantiate each form once & then pass code between the two forms whilst in the dll evironment. Once the user is finished with all forms, I want the dll to close until needed later.

I tried Joe Mamma's code and it I don't think I'll be able to use it. If I understand correctly, Form2 & Form3 inherit Form1's class and only modify the text. Thank you Joe Mamma

In what I want, my forms are completely different but they need to be able to talk to each other as if they were in an exe project.

Thank you again for looking at this & helping me.

I have attached the project that I am trying to run. Please excuse the sloppy programming as I am very new to this & am still learning. - Thanks
 

Attachments

Last edited by a moderator:
Only had a quick glance but it looks like you are never instantiating the form - there is code in the sub main but I don't think that routine is ever called.
Is there a reason why the main application is just an empty form and all the other forms are in the DLL? It just seems a bit confusing in that respect.
also when it comes to passing information between various forms you may want to consider overloading the form's sub new to allow you pass a reference to the calling form. Clicky may be worth a read just to get familiar with the ideas involved.
 
SimDuck said:
I tried Joe Mamma's code and it I don't think I'll be able to use it. If I understand correctly, Form2 & Form3 inherit Form1's class and only modify the text. Thank you Joe Mamma
thats irrelevant.

They could be independent. . .

Drop the VB6 mindset.
on your other issue:
pass the form to another form via a property or method.

Man, VB6 really impeded software development.
 
Thank you both PlausiblyDamp & Joe Mamma.

With your advice and the "clicky" shortcut, I worked it out.

THANK YOU AGAIN. I am very :) now.
 
Back
Top