# Dynamic variable access in Program Error

**URL:** <https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654>\
**Category:** Programming\
**Tags:** automation-studio\
**Created:** [March 26, 2026, 8:52pm UTC](https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654 "2026-03-26T20:52:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanjana\_Jaishankara](https://avatars.discourse-cdn.com/v4/letter/s/FF8800/32.png) [@Sanjana\_Jaishankara](https://community.br-automation.com/u/Sanjana_Jaishankara)\
**Post date:** [March 26, 2026, 8:52pm UTC](https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654/1 "2026-03-26T20:52:35Z")

</div>

I am a student at schmalkalden university, working on the Delta Robot Project, which was built by B&R PLC. I am trying to build modbus communication between B&R plc and Raspberry\_Pi to get x,y value and use in the program(PlotBotPrg).

I wrote program 3, which gets value manually for testing the data type , which worked without any error,

```auto
VAR CONSTANT
  Pos1 : McPointType := (Pos := (X := 0, Y := 0, Z := -431));
  Pos2Base : McPointType := (Pos := (X := 10, Y := 10, Z := -370));
END_VAR

VAR
  Pos2 : McPointType;
  TestX : UINT := 30;
  TestY : UINT := 30;
END_VAR

PROGRAM _MAIN
  
  Pos2 := Pos2Base;
  Pos2.Pos.X := UINT_TO_REAL(TestX);
  Pos2.Pos.Y := UINT_TO_REAL(TestY);
  
  Feedrate(21000);
  
  MoveL(Pos1);
  WaitTime(1.0);
  
  MoveL(Pos2);
  WaitTime(1.0);
  
  MoveL(Pos1);
  WaitTime(1.0);

END_PROGRAM

```

But when I wrote Program 4, using the variable from the communication value,i could build and transfer without error. The logic for pos2 is moving to 0,0,-370, but it should move to 10,10,-370. But in program watch window i see the variable are having the value of X as 10 and Y as 10, no idea why these value are not read in program running

```auto
VAR CONSTANT
  Pos1 : McPointType := (Pos := (X := 0, Y := 0, Z := -431));
  Pos2Base : McPointType := (Pos := (X := 10, Y := 10, Z := -370));
END_VAR

VAR
  Pos2 : McPointType;
  X_Register : UINT;
  Y_Register : UINT;
END_VAR

PROGRAM _MAIN
  
  Pos2 := Pos2Base;
  Pos2.Pos.X := UINT_TO_REAL(X_Register);
  Pos2.Pos.Y := UINT_TO_REAL(Y_Register);
  
  Feedrate(21000);
  
  MoveL(Pos1);
  WaitTime(1.0);
  
  MoveL(Pos2);
  WaitTime(1.0);
  
  MoveL(Pos1);
  WaitTime(1.0);

END_PROGRAM

```

![image.png](https://mail.google.com/mail/u/0?ui=2&ik=f05d63ca10&attid=0.3&permmsgid=msg-a:r6185943754162952361&th=19d2a02eff68fa6d&view=fimg&fur=ip&permmsgid=msg-a:r6185943754162952361&sz=s0-l75-ft&attbid=ANGjdJ9C6TsrZTilx7QSvAbQKiAgqUFZ0P4BjWrzcH59NC10HMjPWxza5bMcFphbFC1gdWk_7NwqgRGY98kjHbvyg9GQaUttgpopJQ7ebJw42-R73-fRjumed35Zxyc&disp=emb&realattid=ii_mn7bugcv3&zw)

now with program 5-it shows syntax error(0) in Visu- i have tried to trigger after reaching Pos1

![image.png](https://mail.google.com/mail/u/0?ui=2&ik=f05d63ca10&attid=0.4&permmsgid=msg-a:r6185943754162952361&th=19d2a02eff68fa6d&view=fimg&fur=ip&permmsgid=msg-a:r6185943754162952361&sz=s0-l75-ft&attbid=ANGjdJ_vcjDIR0LPjaLfo-wRVdg5xmutJ26loq37H2Xfs-LhMDPtKz05Ts7-OPiPX2EUD2ppavpSzpybizfBiS_--pnNMxGeOSbY0_haFcUmdklzoRkSq6Y4DBZSOHA&disp=emb&realattid=ii_mn7doo5o4&zw)

---

<div class="post-metadata">

**Author:** ![michael.bertsch](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/michael.bertsch/32/239_2.png) [@michael.bertsch](https://community.br-automation.com/u/michael.bertsch)\
**Post date:** [March 27, 2026, 8:11am UTC](https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654/2 "2026-03-27T08:11:32Z")

</div>

Hello,

Your Variable Declaration is only defining Variables localy inside the ST-Motion Movement Programm. This Programm is running in a separate Interpreter Context and does have its own Memory Context. If you want to Access data from the PLC you can use the Declaration in the Program, with special Key words or the Configuration of the AxesGroup-Feature Program.

**Declaration in the Program**  
[AS-Help - ST-Motion Programm , Usage of PLC Variables in Motion Program](https://help.br-automation.com/#/en/6/motion/mapp_motion/mapp_robotics/programmierung/programmiersprachen/structured_text/program_content/zuordnung.html)

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/7/7ae76b13444892ee9931af3d057bbf85a9d29c9f.png)

**Declaration in the AxesGroup-Feature Program**  
[AS-Help - AxesGroup Feature Program](https://help.br-automation.com/#/en/6/motion/mapp_motion/mapp_robotics/config/axesgroup_feature/cnc_and_robotic_programs.html)

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/6/68abc9f90da0bcf8ad4b2b5fde40f6fcc9a4ab88.png)

For the Syntax Error i am not yet sure where the difference of the 2 Programs are, but you can go back to first variant and start from there.  
There are some issues with the last 2 pictures, i think its the Limit for your user level, you can post the pictures on an second post again.

Greetings  
Michael

---

<div class="post-metadata">

**Author:** ![michael.bertsch](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/michael.bertsch/32/239_2.png) [@michael.bertsch](https://community.br-automation.com/u/michael.bertsch)\
**Post date:** [March 27, 2026, 8:23am UTC](https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654/3 "2026-03-27T08:23:59Z")

</div>

Hello,

You have used the Variable Initialisation in one of the Programs for local Variables.  
Please be aware that this Initialisation might be confusing, as it is only executed at the load of a program. The program stays in memory and at the second run this inizialisation will be not executed again.  
If there are Start Values for not Constant Variables i recomment to do the inizialisation in the Program.

[AS-Help - ST-Motion Program Variable Inizialisation](https://help.br-automation.com/#/en/6/motion/mapp_motion/mapp_robotics/programmierung/programmiersprachen/structured_text/program_content/variables.html)

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/6/671e28590ff8a877e1f1517bd791741087292b7b.png)

This Inizialisation is only executed once at the first load of the Program.

```auto
VAR
  TestX : UINT := 30;
  TestY : UINT := 30;
END_VAR

```

In this way the Variables get the start Value on each Program Start.

```auto
VAR
  TestX : UINT;
  TestY : UINT;
END_VAR
PROGRAM _MAIN

TestX := 30;
TestY := 30;

END_PROGRAM 

```

Greetings  
Michael

---

<div class="post-metadata">

**Author:** ![kovarj](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/kovarj/32/537_2.png) [@kovarj](https://community.br-automation.com/u/kovarj)\
**Post date:** [April 13, 2026, 5:45pm UTC](https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654/4 "2026-04-13T17:45:31Z")

</div>

Hi @Sanjana_Jaishankara what is the status of your topic?

---

<div class="post-metadata">

**Author:** ![kovarj](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/kovarj/32/537_2.png) [@kovarj](https://community.br-automation.com/u/kovarj)\
**Post date:** [April 19, 2026, 2:55pm UTC](https://community.br-automation.com/t/dynamic-variable-access-in-program-error/10654/5 "2026-04-19T14:55:35Z")

</div>

closed by moderator due to inactivity
