RobotStudio event

Using data across forms

Options

Hello,

I'm quite new at RAB and, admittedly, VS2005.  I am currently facing a problem that doesn't seem to have much information and would greatly appreciate any help on the subject.

Basically, I'm testing out RAB and the different functionalities it offers, and have just created my first "second view".  I would now like to use data that I have gathered from the controller already in my new screen, but I'm always facing the same problem: The name "stringname" does not exist in the current context.

So my question is, how do I use .NET data across forms without having to go read it from the controller every time I switch forms?

Comments

  • RussD
    Options

    A couple of approaches would include making the scope of your variable declarations Public so that they are global within your application or you can pass particular variables or objects into the constructor of your "second view".

    These questions aren't really unique to RAB howver, so you might want to loook at some of them many online resources that would cover these topics in a more general way as a supplement.

    Russell Drown
  • ATess
    Options

    Here is roughly what I did.  It does compile, and it doesn't generate an error when I run the program.  But... the text is never displayed, so I'm guessing there's an error SOMEWHERE!
    I feel like I'm so close to the goal, please guide me.
    public
    class view2 : TpsForm
    {
    private ABB.Robotics.Tps.Windows.Forms.MenuItem menuItem1;

    private System.ComponentModel.IContainer components = null;
    private TpsViewMainScreen _view1;
    string stThisIsText;
    public view2()
    {
    InitializeComponent();
    _view1 =
    new TpsViewMainScreen();
    menuItem1.Click +=
    new EventHandler(menuItem1_Click);
    stThisIsText = _view1.stThisIsText;
    this.Text = "Menu name: " + stThisIsText;
    }
  • RussD
    Options

    try this, which uses a n overridden constructor which passes in a parameter from view1

    you would call it like _view2 = new view2("view 1 text");

    public class view2 : TpsForm


    {
    private ABB.Robotics.Tps.Windows.Forms.MenuItem menuItem1;

    private System.ComponentModel.IContainer components = null;

    string stThisIsText;

    public view2()

    {

    InitializeComponent();

    }

    public view2(string View1Text)

    {

    InitializeComponent();

    menuItem1.Click += new EventHandler(menuItem1_Click);

    this.stThisIsText = View1Text;

    this.Text = "Menu name: " + stThisIsText;

    }

     

    Russell Drown
  • ATess
    Options

    As I understand it (I haven't had a chance to try it yet, kind of doing 2-3 things at a time here :S), this directly gives string as a parameter to the next screen, correct?

    So it should work if I only have 1-2 things to transfer, but if I need to pass 5+ elements, I'm assuming there's a more general way of making data available to other screens?

  • ATess
    Options

    I took the time to try out your suggestion.  It does indeed work and could be used as a workaround until I figure out how to access data more directly across differents forms.

    I know google is my friend and that there's a lot of information I can find on the subject there, but I'm not quite sure on how to word my search and find what I'm looking for.

  • RussD
    Options
    If you need to pass the same data over and over again, you can just create your own datatype, i.e. a class, and pass that as an argument, otherwise, you should look at the scope of the data  you are interested in and make sure it can be "seen" by other classes, lfor instance declaring it as public.
    Russell Drown
  • ATess
    Options
    I've created a public class with public variables in it.  I create an instance of it in my first screen, and then pass it as an argument to my second screen.  I'm not sure if that's the proper approach to go with, but it certainly did work.  Thank you!