Passing info to an open form

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

How can I pass some text info to my start-up form from an external sub in a
module?

Thanks

Regards
 
You can create a class, and then use a parameter you write and read from.

The sub writes to the class...
the from reads from the class.

Miro
 
John wrote : " How can I pass some text info to my start-up form from an
external sub in a module?"

Miro replied : "You can create a class, and then use a parameter you write
and read from. The sub writes to the class ... the from reads from the
class.

2nd. message from John in response to Miro ... :

"How does form know when to read ? Ideally it should be immediate."

Hi John,

I'm going to assume you are talking about a situation where you are
describing a typical start-up Form, launched when the app starts, shown from
time to time as the end-user wishes to see it ... right ?

I'm also going to assume that that the information the start-up form needs
to display is, in this case not static ... right ?

Everything that follows assumes the StartUp Form and the other Form with the
sub that calculates the data needed to be displayed on the StartUp Form are
in the same Project, in the same NameSpace ... right ?

The issue of when the start-up Form needs to read the information it will
display can be addressed by creating an Event handler for the start up Form,
like for the VisibleChanged event, or the Activated event. Or you can have
one call in your main form that launches the StartUp Form.

There are several techniques you can use to allow the start-up form to read
or the other form to "publish" the information : as Miro suggested define a
Class with a public property of type String called 'StartUpData with get and
set handlers.

You could "inject" a reference to the form in which your sub is embedded
into a public variable (or Property) in the start-up Form when you
Application starts (in the Application Load even, for example). You could
preserve a private reference variable to the start up Form's components you
need to write data to in the Form where you sub is, again perhaps using the
main app's Form load event to access these (you'd have to make the
components public, or you'd have to defne some public variables in the
StartUp form to allow access.

My own personal choice for a technique would be to define a single public
static class containing static variables in the Main app's NameSpace :

// C#
// note : this will compile and work fine with no using statements !
using System;

namepace mainAppNameSpace
{
public static class staticData
{
public static string strData1;
public static int intData1;
public static double dblData1;
}
}

For me I use this technique because I most often have several independent
top-level windows running any one of which might need to write or read the
data in the StaticData class. But obviously the data in these static
variables must be global. In other situations I personally believe it is
better to write formal Properties with tight control of whether set/get
handlers are implemented

best, Bill
 
Back
Top