Author Topic: using a temporary table  (Read 2168 times)

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
using a temporary table
« on: February 16, 2019, 03:48:04 PM »
Dear All,
In my code, I read an "X" variable that exists in a temporary table in another application (which I read this variable through the OPC server).

I want to keep this variable "X" in another temporary table in my code even after the disappearance of the table of the other application.

whenever the variable "X" changes in the temporary table of the other application, I must create a new column in my temporary table and save it in it.

Thx

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: using a temporary table
« Reply #1 on: February 16, 2019, 04:03:15 PM »
When you refer to "table", do you mean a database table?

Phrog30

  • Guest
Re: using a temporary table
« Reply #2 on: February 16, 2019, 04:14:00 PM »
Here's my suggestion, tell us what you are trying to do, not how you want to do it. A lot of times programmers think they have the best approach, then ask how to do it. Instead, explain the process, then let others give their opinions on how to tackle it.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: using a temporary table
« Reply #3 on: February 16, 2019, 04:47:57 PM »
Thank you for your answers.
simply, I want to store values that exists in a table of an application that communicates with the PLC (which I read through OpcDaCom).
This table is temporary, it changes these values for each new production order.
I want to store his contents so that I can do other treatments afterwards.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: using a temporary table
« Reply #4 on: February 16, 2019, 10:23:21 PM »
What you have described sounds like an Excel table in which you would have a column for each value and just keep populating its rows with each change of the value.

EPPlus package could be used if you don't have Microsoft Excel.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: using a temporary table
« Reply #5 on: February 17, 2019, 07:43:19 AM »
it sounds a bit like what you said.
in fact, I want to save values that come from a temporary database (from another
production management application) via opc.
because the values change all the time, I have to save them to another table in my program with incrementing each time the values change.
I used variables but it did not work because with each change it crushes the previous value.
« Last Edit: February 17, 2019, 07:45:12 AM by MEDALI1TN »

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: using a temporary table
« Reply #6 on: February 18, 2019, 03:59:19 PM »
if i can fill a Datagridview column with a Variable i think i can solve my problem.
thank you

Phrog30

  • Guest
Re: using a temporary table
« Reply #7 on: February 18, 2019, 04:20:29 PM »
I'm not the best to answer, but a datagridview DGV is really nothing more than a way to view data, a table. Are you binding the DGV to something? If you bind, then whenever the source changes it will change. But, I believe I'm right in saying if you want to change a bindable DGV it's not so straightforward.

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: using a temporary table
« Reply #8 on: February 18, 2019, 04:37:03 PM »
i'm not binding the DGV to nothing, just i want to save some variable that i read with OPC to a temporary table ... and i think that the DGV can help me.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: using a temporary table
« Reply #9 on: February 18, 2019, 04:43:48 PM »
Why do they have to be saved in a table? Why not just store them in an array?

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: using a temporary table
« Reply #10 on: February 18, 2019, 04:51:20 PM »
if i can keep the values of the variables even after they change it will be better.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: using a temporary table
« Reply #11 on: February 18, 2019, 04:56:00 PM »
So you want a history of the values? Do they have to be displayed in a table?

MEDALI1TN

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: using a temporary table
« Reply #12 on: February 18, 2019, 04:59:16 PM »
no it's not very important.
the most important thing is to be able to do tests in my program and I need the history of the variables.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: using a temporary table
« Reply #13 on: February 18, 2019, 05:06:36 PM »
This is one way I would go about it.

- Create a class that defines a variable for each value you retrieved (In the CLX world this would be equivalent to a UDT)
Code: [Select]
Public Class MyItems
  Public Item1 as string
  Public Item2 as Integer
End Class

- Create a List to store the items in
Code: [Select]
Public ItemStore as new List (Of MyItems)

- Each time you retrieve the data, create an instance of the class and store the values in it.
Code: [Select]
Dim MyValues as new MyItems
MyValues.Item1 = "ABC"
MyValues.Item2 = 123

- Add the new class instance to the list
Code: [Select]
ItemStore.Add(MyValues)

You will now be able to retrieve the history as an array
Code: [Select]
MsgBox("Item1=" & ItemStore(0).Item1

Phrog30

  • Guest
Re: using a temporary table
« Reply #14 on: February 18, 2019, 06:31:22 PM »
You haven't been very clear on the data structure you are looking at in the PLC. But what i visualize is an array of data. So I would use a database and when you read via opc I would add a row in the database with the array ID, actual value, and a timestamp. Then you can easily query, plus it's an actual history, meaning the data will survive after you close the application.