Use of Instances

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
Jwphilippi
Posts: 13
Joined: Mon Mar 11, 2013 8:48 am

Use of Instances

Post 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;
}

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: Use of Instances

Post 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
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Use of Instances

Post by mark.monroe »

You might want to take a look at this forum post for some example code.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

Jwphilippi
Posts: 13
Joined: Mon Mar 11, 2013 8:48 am

Re: Use of Instances

Post by Jwphilippi »

Sorry, I know my explanations are as clear as mud. Here is an example of the code...
Attachments
Example.png
Example.png (21.29 KiB) Viewed 11601 times

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: Use of Instances

Post 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
Attachments
iX_Instance_Switch.zip
(30.08 KiB) Downloaded 818 times
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: Use of Instances

Post 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
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

Post Reply