• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Message Passing between 2 classes

I have a single program. Class A reads messages from a control box. I need to display this message on my dialog box(class B). Hence i create an instance of A in B. Now i need A to pass the message to B. Currently i have a fnction with a flag that i loop(in class B). Once a message is available in class A, class B reads the message and resets the flag. Is there a more efficient way to do this.
Thanks,
Anthony
0
antiwong
Asked:
antiwong
  • 3
  • 2
2 Solutions
 
JayhpotCommented:
i think placing the message to a global variable will do the trick... both classes will recognize the value of that variable
0
 
CoenMeerbeekCommented:
Is this what you mena?

Class A
{
  public String getString()
  {
     return TextBox.text;
  }
}

Class Main
{
  A a = new A();
  B b = new B();

  String s = a.getString();

  b.setString(s);
}

Class B
{
  private String str;

  public setString(String s)
  {
    str = s;
  }
}

Good luck
0
 
CoenMeerbeekCommented:
Is this what you mena?

Class A
{
  public String getString()
  {
     return TextBox.text;
  }
}

Class Main
{
  A a = new A();
  B b = new B();

  String s = a.getString();

  b.setString(s);
}

Class B
{
  private String str;

  public setString(String s)
  {
    str = s;
  }
}

Good luck
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JayhpotCommented:
well, i don't know what language u are using but whatever it is, i know it has a capability to declare a global/public variable which any class or function can use.

in vb, we create a global module (ex: modGlobal.bas) declaring all global variables in our program.

ex:

Global strMessage As String

that variable is accessible to any class/function/procedure.

ex:

function initial(){
   strMessage = text1.text
}


function getMsg(){
   label1.caption = strMessage
}

0
 
CleanupPingCommented:
antiwong:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
JayhpotCommented:
since i'm the only one who answered it, i might as well recommend that my answer be accepted
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now