Communication between Forms in VB.Net

ROMIO

Member
Joined
Sep 3, 2006
Messages
7
Programming Experience
Beginner
Hi everybody,
Using VB.Net, I need to get a comunication between 2 forms but without using for shared variables since each form know nothing about the other, I thougt that each form has its own variable which both refernce to the same place in memory (as pointer in other languages), How can I do this using VB.Net.
Thank you.
 
Add public property/method to the (form) class and communicate through this.
 
Hi everybody,
Using VB.Net, I need to get a comunication between 2 forms but without using for shared variables since each form know nothing about the other, I thougt that each form has its own variable which both refernce to the same place in memory (as pointer in other languages), How can I do this using VB.Net.
Thank you.
I suggest that you brush up on your object-oriented programming. Even if you could do that, how would the two forms who know nothing of each other get the same memory address to reference the same value? If there is a genuine reason that neither form can have a reference to the other, which I'm guessing that there isn't, then they are both going to have to have access to a variable somewhere that they are both aware of, like in a parent form or a module.
 
Thanks a lot, but let explain what I need to do, I have a global shared variable where 2 forms able to access it (read & write), but I'm planing to put each of these 2 forms in different dll file so they will not able to access the shared variable anymore unless I put it as parameter for each but here I want to have a 2 references for the same variable inorder to have the same functionality as the shared variable. Thx.
 
From the sound of things your design is flawed. It sounds to me like you should be passing this data to each of these forms through constructors, other methods or properties. Failing that then each library should have a reference to another library that contains either a class with a Shared member or a module that both forms can then access. That is a poor second choice in my opinion though.
 
Might want to read up on Delegates and EventHandling. I had a similar situation (except it was user controls, and both are in the same project) where I needed forms to communicate w/ each other. I solved it by adding events to the UC, then wrote an event handler in the parent form to catch the events, process the message, then send it on to the appropriate UC through public functions. I was then able to further extend the functionality by creating a custom EvenHandlerArgs class, and using it to pass around my newly custom made messages.

-tg
 
Thank you people, I solved this by putting all the shared variables inside a DLL file and taking a reference about it by each Form.
 
Back
Top