Page 1 of 1

Use of Instances

Posted: Thu May 09, 2013 8:52 am
by Jwphilippi
I have a scenario where I have a screen with multiple aliases and instances that are directly related to analog numeric text boxes.

(Scenario: Instances - w1, w2, w3
Aliases - a1, a2, a3
a1 a2 a3
w1 tag1_1 tag2_1 tag3_1
w1 tag1_2 tag2_2 tag3_2
w1 tag1_3 tag2_3 tag3_3)

I have the screen dynamically select an instance based on an internal tag which increments or decrements based on the user selected well and thus the tag in the alias referenced should change but unfortunately it is not. Any Ideas?
Using the following for the screen change

switch(Globals.Tags.SelectedInstance.Value.Int)
{
case 0:
Globals.Screen.W1.Show();
break;
case 1:
Globals.Screen.W2.Show();
break;
case 2:
Globals.Screen.W3.Show();
break;
}

Re: Use of Instances

Posted: Mon May 13, 2013 11:04 am
by Edmund
Hi!

If you post your project I´m sure we can help you, but it´s a bit hard to see the problem from your explanation...

Best Regards

Re: Use of Instances

Posted: Mon May 13, 2013 11:16 am
by mark.monroe
You might want to take a look at this forum post for some example code.

Re: Use of Instances

Posted: Tue May 14, 2013 9:59 am
by Jwphilippi
Sorry, I know my explanations are as clear as mud. Here is an example of the code...

Re: Use of Instances

Posted: Wed May 15, 2013 2:36 am
by Edmund
Works good for me, I also made some changes/improvements...

Code: Select all

void btnBack_Click(System.Object sender, System.EventArgs e)
		{
			GetInstance(--Globals.Tags.Selected_Insance.Value);
		}
		
		void btnNext_Click(System.Object sender, System.EventArgs e)
		{
			GetInstance(++Globals.Tags.Selected_Insance.Value);
		}
		
		void GetInstance(int newInstasIndex)
		{
			switch(Globals.Tags.Selected_Insance.Value.Int)
			{
				case 0: Globals.Tags.Selected_Insance.Value = 0; break;
				case 1:
					if(this.InstanceName != "Instance1")
						Globals.Instance_Window.Instance1.Show();
					break;
				case 2:
					if(this.InstanceName != "Instance2")
						Globals.Instance_Window.Instance2.Show();
					break;
				case 3:
					if(this.InstanceName != "Instance3")
						Globals.Instance_Window.Instance3.Show();
					break;
				case 4: Globals.Tags.Selected_Insance.Value = 3; break;
			}
		}
Try the attached project

Best Regards

Re: Use of Instances

Posted: Wed May 15, 2013 4:08 am
by Edmund
CRAP!

There was an error in my previous post (and attached project).

In the switch statment and case 0, it set the current instance to zero but it should have been 1.

So if you try please change it to

Code: Select all

case 0: Globals.Tags.Selected_Insance.Value = 1; break;

Regards