2

I want to take a string that contains the symbol name of a variable and somehow get the address and size of the variable with that symbol name.

MyDINT:= 5;
MySymbolName:= `MyDINT`;

VariableInfo:= SomeFunctionImLookingFor(MySymbolName);
MyDINTPointer ACCESS VariableInfo.Address;
MyDINTSize:= VariableInfo.Length;

NOTE: This is different from __VARINFO(MyDINT); because I would be passing the symbol name MyDINT as a string.

EDIT: This is obviously not my use case, just the simplest possible example. I find it curious that there is a function that will return a symbol name as a string but not one that goes the other way around.

CapinWinky
  • 748
  • 7
  • 8
  • Why would you even do this? If what you need is to pass a variable of any size, just use the `ANY` type. If you don't want/can't use `ANY`, just make a structure with a `POINTER TO BYTE` and an integer type for size, and pass that instead of the string. And if you must pass the name of the variable too, just include that in the struct as well. – Guiorgy Jan 07 '22 at 21:44
  • 1
    Hi CapinWinky, welcome to StackOverflow. Why would you want to use the string and not the variable name itself? Even if it would work with the string, using the variable name directly would be much better. For example: what if you rename `MyDINT` to something else? The refactoring tool will not rename the string variable name. – Roald Jan 08 '22 at 09:44
  • This is to streamline code deployment in a simple and scalable way. I do this with B&R already and it works great. The exact same code can handle one axis or 1000 axes without changing a single character (same with temperature loops and other such things). Admittedly, the code changes required to do this long-hand are only two or three lines per group, that's something I would need to setup every project that I simply don't have to do in my B&R projects. I also use this mechanic in my IO diagnostics screens, but this isn't the only missing functionality I've run into for that usecase. – CapinWinky Jan 25 '22 at 14:27

0 Answers0