SimDuck Posted November 7, 2004 Posted November 7, 2004 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 Quote
Administrators PlausiblyDamp Posted November 7, 2004 Administrators Posted November 7, 2004 Any chance you could post the code you are using to display the form from the DLL? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Joe Mamma Posted November 7, 2004 Posted November 7, 2004 see attached solutionSharedForms.zip Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
SimDuck Posted November 8, 2004 Author Posted November 8, 2004 (edited) @ 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. - ThanksAdd_Trans.zip Edited November 8, 2004 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted November 8, 2004 Administrators Posted November 8, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Joe Mamma Posted November 8, 2004 Posted November 8, 2004 I tried Joe Mamma's code and it I don't think I'll be able to use it. If I understand correctly' date=' Form2 & Form3 inherit Form1's class and only modify the text. Thank you Joe Mamma[/quote']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. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
SimDuck Posted November 17, 2004 Author Posted November 17, 2004 Thank you both PlausiblyDamp & Joe Mamma. With your advice and the "clicky" shortcut, I worked it out. THANK YOU AGAIN. I am very :) now. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.