Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Too many frmA's

Status
Not open for further replies.

thornmastr

Programmer
Feb 2, 2002
1,337
0
0
US
Hello,

I am using Visual Basic 6.0 SP6 with Windows XP SP2.

I have two MDI child forms; call them frmA and frmB. FrmA calls frmB. On frmA is an an MSHflexgrid which has information needed on frmB. Of course, referencing information on frmA from frmB immediately creates a
brand new frmA so that if the information I want is on frmA row 2, I obviously get the information on row 1 of the brand new frmA.

One obvious solution is to keep the required information in a global module however I do not want to have global variables when I don't need them and I really don't think this is a necessary or a correct solution.

All I want to do is to get the information from the frmA that called frmB. I certainly do not want the new frmA.

I am sure there are more viable solutions than global variables. Any
suggestions, hints, and further information is certainly appreciated.

Thank you,

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
Set up a property on frmB. You can use property procedures or a public variable. When you call frmB from frmA, set frmB's property to whatever value you want to from the grid on frmA. Then frmB can access the value whenever it wants to.

HTH

Bob
 
Bob,

Thank you. It worked perfectly.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
Of course, by doing that you have basically introduced the global variable you were hoping to avoid ... ;-)
 
Yes, I noticed that. However, it is global to frmA and only while frmB is active. It is a very small class activated immediately before frm b is opened and destroyed when frmB closes so, at least, it is not global across the
application.

<sigh>. I've asked this question in a number of newsgroups and this seems to be the favored methodology. In fact, out of four newsgroups, it is the only suggestion I have gotten. And, of course, it does work. From a purist point of view, I would like to see other ideas but unfortunately there is a derth of
activity in that arena.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
StrongM,

Someone on a newsgroup finally saw the real problem. I was not using the real name for frmA. Instead I was using an Object variable name. I then referred to the form by its real name rther than the object reference in frmB which created another frmA referenced by the correct name.

The obvious solution was to open frmA with the name "frmA" rather than an object variable name.

Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@earthlink.net
 
Yes, I rather suspected something like that was the case. Of course, from a certain point of view, the default instance of a form ("frmA") is a global variable ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top