Declare Variables at Run time

Jonas

Member
Licensed User
Longtime User
Im creating a program that is going to be similar to an HMI.
It will update the tags from a web service.

I have a XML file with all available tags I can receive from the web service.
Every tag has its unique ID, Name, Description, Type of variable and so on.

It can look something like this:
ID: 1
Name: Machine.State.RPM.Actual
Description: Actual Machine RPM
Type: float
Unit: RPM

I do not want to add all tags manually so I figure doing it by using XMLSAX.

When all tags are added Im thinking using the ID number to find the tag of interest,
B4X:
Label1.Text = Tags(ID).ActualValue
or
B4X:
Label1.Text = Tags(Label1.Tag).ActualValue & Tags(Label1.Tag).Unit

What will be the best practice to declare all tags into variable structure?
The Tag().Actual can be string, integer, float, unsigned or DateTime.
When I receive an update from the web service it comes as String and also with information of variable type.
Or should I always declare the Tags().ActualValue as string and deal with it when it needs to be converted?

Also when I receive an update it wont say the ID number of the tag, just the name of it. So to find where I should update inside the Tags() variable I need to make a loop that looks for a match at Tags(index).Name

I hope my explanation make sense or I will try it in an other way.

/J
 

Jonas

Member
Licensed User
Longtime User
Ok Ill try to explain it in an other way.

In the tag definition file each tag has some properties.

Here is an exemple of three:

ID: 1
Name: Machine.State.RPM.Actual
Description: Actual Machine RPM
Type: float
Unit: RPM

ID: 2
Name: Machine.State.Current.Actual
Description: Actual Machine Current
Type: unsigned
Unit: A

ID: 3
Name: Machine.State.Time.Actual
Description: Actual Machine Time
Type: DateTime
Unit:


I want in a way create a custom Type like,
B4X:
Type Tag() (ActualValue as YetUnknown, Name as String, Description as String, VarType as String, TagUnit as String

When I go through the tag definition file and add the tags into an array I check the Type properties of the tag and then I want to Dim the ActualValue as the tag type.

So,
Tag(1).ActualValue will be Dimmed as Float
Tag(2).ActualValue will be Dimmed as Int
Tag(3).ActualValue will be Dimmed as Long

Or should I try to go another way?
My plan is to make it as easy as possible to use the tags in diffent parts of the program, sometimes as texts, sometimes as values in an equation or used in a graph.

/J
 
Upvote 0
Top