Tag value change in screen script

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
stm-tjt
Posts: 7
Joined: Wed Nov 07, 2018 6:08 am

Tag value change in screen script

Post by stm-tjt »

Hi,

I am researching the opportunity to create a dynamically populated list box based on this sample program, however I'd like to call the function when a specific tag becomes true instead of when pressing a button.

Is there a way to do either of these options:
  1. Call a function from the screen script from the Tags script, or
  2. Detect the value change of the trigger tag from the screen script
Copying this code snippet from Tags script to Screen1 script does not work (never executed):

Code: Select all

void TrigUpd_ValueChange(System.Object sender, Core.Api.DataSource.ValueChangedEventArgs e)
		{
			// MessageBox.Show("Value change code executed");
			// Call code to update listbox from tag
		}
and I cannot find a way to reference my function in the Screen1 script file to update the listbox, e.g.

Code: Select all

public void GetArrayFromTag()
		{
			// MessageBox.Show("Listbox update code executed");
			// Code to update listbox from tag
		}
from the Tags script file.

Thanks in advance. Let me know if you need additional information or access to the project.

prichlin
Posts: 18
Joined: Thu Feb 20, 2020 7:59 am

Re: Tag value change in screen script

Post by prichlin »

Hello stm-tjt,
I took a quick look at this and have a suggestion you can try but it's probably not the most direct approach. I think it does what you're looking for. I would encourage you to find a better solution.

I think the main challenge here is generating an event on the screen so you can run the script to update the list box; maybe try a ValueChange event on a hidden object.

1. Make a new Tag RequestListBoxUpdate
2. On the page with the list box, add an Analog Numeric value field. In the Tag field, assign RequestListBoxUpdate and turn off the Visibility so the operator can't see or interact with this field.
3. Add a ValueChanged event to the Analog Numeric field and use the code below.

Code: Select all

public string[] newStringArray = new string[5];

void AnalogNumericRequestUpdate_ValueChanged(System.Object sender, Core.Api.DataSource.ValueChangedEventArgs e)
{
	if(e.Value.ToString() == "0")
	{
		; //no update
	}
	else if(e.Value.ToString() == "1")
	{
		//Replace this with the choices you want to appear in the dropdown
		newStringArray[0] = "Apple";
		newStringArray[1] = "Banana";
		newStringArray[2] = "Chocolate";
		newStringArray[3] = "Orange";
		newStringArray[4] = "Pear";

		UpdateFinalArray(newStringArray, ref finalStringArray);
		Add_TouchComboBoxValue(ref m_TouchComboBox, finalStringArray.Length, finalStringArray);
	}

	Globals.Tags.RequestListBoxUpdate.Value = 0; //update finished	
}
When the tag you're using with the new dropdown choices is ready (not shown here), set RequestListBoxUpdate to 1 to update the list box.

Hope this helps!

stm-tjt
Posts: 7
Joined: Wed Nov 07, 2018 6:08 am

Re: Tag value change in screen script

Post by stm-tjt »

prichlin wrote:
Fri Jun 26, 2020 8:30 am
Hello stm-tjt,
I took a quick look at this and have a suggestion you can try but it's probably not the most direct approach. I think it does what you're looking for. I would encourage you to find a better solution.

I think the main challenge here is generating an event on the screen so you can run the script to update the list box; maybe try a ValueChange event on a hidden object.

1. Make a new Tag RequestListBoxUpdate
2. On the page with the list box, add an Analog Numeric value field. In the Tag field, assign RequestListBoxUpdate and turn off the Visibility so the operator can't see or interact with this field.
3. Add a ValueChanged event to the Analog Numeric field and use the code below.

Code: Select all

public string[] newStringArray = new string[5];

void AnalogNumericRequestUpdate_ValueChanged(System.Object sender, Core.Api.DataSource.ValueChangedEventArgs e)
{
	if(e.Value.ToString() == "0")
	{
		; //no update
	}
	else if(e.Value.ToString() == "1")
	{
		//Replace this with the choices you want to appear in the dropdown
		newStringArray[0] = "Apple";
		newStringArray[1] = "Banana";
		newStringArray[2] = "Chocolate";
		newStringArray[3] = "Orange";
		newStringArray[4] = "Pear";

		UpdateFinalArray(newStringArray, ref finalStringArray);
		Add_TouchComboBoxValue(ref m_TouchComboBox, finalStringArray.Length, finalStringArray);
	}

	Globals.Tags.RequestListBoxUpdate.Value = 0; //update finished	
}
When the tag you're using with the new dropdown choices is ready (not shown here), set RequestListBoxUpdate to 1 to update the list box.

Hope this helps!
While I agree that it is a bit of a hack to achieve what I want, it does provide the intended functionality. If I do not find another solution before we commission the line, I will put this to use.

Thanks a lot for the suggestion prichlin :D

Post Reply