2nd window instance acts upon 1st

I’ve created a serial terminal window. Today I need to have two terminal windows open, as I want to monitor two serial ports.
So I put a button on my terminal window, to create a new instance, as explained elsewhere in this forum.
That works fine. The funny thing that happens though, is that when I type into window 2, the text I type goes to to window 1. I haven’t studied this yet, but it raises some questions.

Question: There needs to be a way to differentiate these windows. The window has been called ComWnd, but now there are two of them, what are they each called? Is this an array of windows now? What happens to code that is referencing ComWnd?

Question: If ComWnd has a property, does each instance have its own copy of that property? Would a shared property be common to all window instances?


You can create an array of the windows… Lets say you have the menu item File > New and it creates a new window… In the App class you would add the MenuHandler for FileNew (or whatever you named the menu item), create a private property on the App class (mWindows() As Window) The MenuHandler code could be something like the following

DIM newWindow As NEW ComWnd // this allows you to have access to the window in the handler without having to access the array all the time App.mWindows.Append newWindow newWindow.Show

If each ComWnd instance has a property, it is specific to that instance… A shared property would be common to all the windows and changing it on one window would change it for them all…

Thank Shao for your reply.

It looks like the first window is still called ComWnd, because calls were being made that referred to ComWnd, and these were causing the problem. That is, there were calls in the code of ComWnd that referred to ComWnd by name, and those were sending the characters to the first window. Having fixed that, it works fine.

Still don’t know what the name of the second window is. Not a problem at the moment but will need to figure that out. I suppose MsgBox (Me.Name) might provide the desired info.


It too will be named ComWnd :stuck_out_tongue:
They are both instances of the ComWnd CLASS

However I suspect you have implicit instance enabled for this window
What happens is that the first one opened will be accessible using the global name “ComWnd”
So everything that says “ComWnd.whatever” to set a property or access a control will go to the first one opened

I would turn OFF implicit instance
I guarantee you’ll find lots of dependencies in your code that now break
Depending on where that code is it may be easy to fix … or not

I habitually turn off implicit instance. I’ve only found it to cause trouble.