Features, discussions, tips, tricks, questions, problems and feedback

Write agent value with VB.net

Hello

I have been working with maps for a year now. This is goning well.
But now I’m working on VB.NET scripting. I’m running into some problems.

It’s about writing a value to an agent.
Below is my code.

 'Initializes Event Handlers and Control Name Bindings
	Private Sub button_Click(sender as System.Object, e as System.EventArgs) Handles button.Click
	Dim dec As DataElementCollection = VIZNET.Shared.DataElements.Engine.DataElementEngine.NewDataElementCollection()

	Dim agent1 As DataElement = VIZNET.Shared.DataElements.Engine.DataElementEngine.NewDataElement("Adroit.Analog.TST_PLC_NUMBER.value")

	agent1.value = 5

MessageBox.Show("Successfully executed script")
	End Sub`Preformatted text`

The value does not change in the plc.
The messageBox works fine.
What am I doing wrong.

Can you help me.

Greetings,

A.J.

You need to update your collection after changing values (send data to server)
Connection.UpdateDataElements(__dec);

As per Damian’s comment, you are setting the value of the object, but you are not sending the object to the server. You are simply changing it in the local variable. You still need to send the collection to the Server.

The VB code:

'add the data element to the collection
  dec.add(agent1)
'send the data element collection to the Server
    MyConnection.UpdateDataElements(dec)

Thank you for your reply.

I will test this when i’m back in the office.

Hello guys,

Thank you for the help. Thit was the solution

But thit raisd a new question.

How can I get the agent in a ‘public’ class. So that i can use the same agent multiple times.

This what i made but in does not work.

“Agents” reside within the Server environment and not within the Client / Operator. The DataElement and DataElementCollection is simply used to represent the values that need to change within a specific DataSource - in this case the Adroit Data Source.

Specific VB language questions are beyond the scope of this forum. Also note that scripting provides a lot of power and flexibility, but needs to be used responsibly as it can introduce additional complexity. Classes should not be defined within the script, but can be used within a separate library instead (DLL reference).

The use of Global Client Side variables are discussed here: Global Client Side Variables - SmartUI - Features, discussions, tips, tricks, questions, problems and feedback (adroittechnologiesautomation.com) (translating to VB should be relatively straightforward).

Thankt for your anstwer,

I will read the other disscusion