Using data across forms
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
-
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 Drown0 -
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;
}0 -
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 Drown0 -
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?
0 -
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.
0 -
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 Drown0
-
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!0
Categories
- All Categories
- 5.5K RobotStudio
- 394 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 309 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings