# Reading and writing texts to string variables

**URL:** <https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378>\
**Category:** HMI & Visualization\
**Tags:** mapp-view, automation-studio\
**Created:** [February 27, 2024, 9:20pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378 "2024-02-27T21:20:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_Lin2](https://avatars.discourse-cdn.com/v4/letter/j/FF8800/32.png) [@Jack\_Lin2](https://community.br-automation.com/u/Jack_Lin2)\
**Post date:** [February 27, 2024, 9:20pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/1 "2024-02-27T21:20:30Z")

</div>

Hi guys,  
I was wondering if it was possible to read or write the texts in the tmx files to string variables? If it is, how would it interact with changing languages?

---

<div class="post-metadata">

**Author:** ![austin.carpenter](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/austin.carpenter/32/1196_2.png) [@austin.carpenter](https://community.br-automation.com/u/austin.carpenter)\
**Post date:** [February 27, 2024, 9:55pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/2 "2024-02-27T21:55:07Z")

</div>

Hello JackLin,

You can use the ArTextSysGetText() function block to obtain the text from a known Namespace and TextID. An input to the function block is the Language you would like to obtain for that TextID.

[ArTextSysGetText() - B&R Online Help (br-automation.com)](https://help.br-automation.com/#/en/4/libraries%2Fartextsys%2Ffunktionsbausteine%2Fartextsys_artextsysgettext%2Fartextsys_-_artextsysgettext%28%29.html)

Remember that the encoding is different coming out of the text system (UTF-8), so you will need httpUtf8ToWString() from the AsHttp library to convert them to WSTRING.

---

<div class="post-metadata">

**Author:** ![Jack\_Lin2](https://avatars.discourse-cdn.com/v4/letter/j/FF8800/32.png) [@Jack\_Lin2](https://community.br-automation.com/u/Jack_Lin2)\
**Post date:** [February 28, 2024, 4:35pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/3 "2024-02-28T16:35:15Z")

</div>

Hey Austin, my Automation Studio doesn’t have these function blocks. I’m on version 5.24.1. Is there somewhere where I can download the library for these?

---

<div class="post-metadata">

**Author:** ![wenbo.ruan](https://avatars.discourse-cdn.com/v4/letter/w/FF8800/32.png) [@wenbo.ruan](https://community.br-automation.com/u/wenbo.ruan)\
**Post date:** [February 28, 2024, 5:08pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/4 "2024-02-28T17:08:42Z")

</div>

Hello JackLin:

I’m assuming the 5.24.1 is version of mapp Components, as AS is still on Version 4.XXX. Regarding the function block ArTextSysGetText(), is on the library [ArTextSys](https://help.br-automation.com/#/en/4/libraries%2Fartextsys%2Fartextsys.html)  
You don’t need to download the library, as it already in AS. you only need to add them to your project to use them. To do so: In the toolbox, click on B&R Library,

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/b/b2d1f2b2235f689c7e6c35a56619b2acf869e137.png)  
And the select the ArTextSys  
 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/1/1dfb5d6d803fb54b039c449d1e17654222786e99.png)

With this, you have the library added to your project.

Hope it helps

---

<div class="post-metadata">

**Author:** ![Jack\_Lin2](https://avatars.discourse-cdn.com/v4/letter/j/FF8800/32.png) [@Jack\_Lin2](https://community.br-automation.com/u/Jack_Lin2)\
**Post date:** [February 28, 2024, 6:01pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/5 "2024-02-28T18:01:09Z")

</div>

Alright, I got the function blocks. How do I format Namespace and TextID though? Based on the formatting help file, this is my attempt but its not working.

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/d/d7ef632a1f18b1f88646e547edb7926e47c745d2.png)  
What does the help file mean when it says Namespace is datatype: UDINT  
(given as a pointer to STRING)??

---

<div class="post-metadata">

**Author:** ![alexander.hefner](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/alexander.hefner/32/111_2.png) [@alexander.hefner](https://community.br-automation.com/u/alexander.hefner)\
**Post date:** [February 28, 2024, 6:33pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/6 "2024-02-28T18:33:41Z")

</div>

Hi,

that means that the address of a string variable has to be used instead of the string variable itself.  
An address (= position of the memory in RAM, where the data of the variable is stored / begins) in B&R System always has 4 byte, so it’s of the type UDINT.

```iecst
// this is my string variable
myString := 'this is my string value';

// this is the pointer of type UDINT
myPointer := ADR(myString);

```

---

<div class="post-metadata">

**Author:** ![Jack\_Lin2](https://avatars.discourse-cdn.com/v4/letter/j/FF8800/32.png) [@Jack\_Lin2](https://community.br-automation.com/u/Jack_Lin2)\
**Post date:** [February 28, 2024, 7:37pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/7 "2024-02-28T19:37:37Z")

</div>

Ok I’m almost there. The last thing I don’t understand is, after I run artextsysgettext(), where does the utf-8 result go? (Ignore everything above GetText)

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/1/173475b7eef99bb8d6f5993e8fb725feb56fe19b.png)  
None of the 5 outputs in artextsysgettext() are the actual results, the only string-outputs are textSize and statusID. I don’t know what to put in pSrc in my httputf8towstring function. Here, I tried directly putting “GetTextI01” (which is the tag for my function) in pSrc, but its not working.

Speaking of httputf8towstring, when that function completes, where does that output go?

---

<div class="post-metadata">

**Author:** ![alexander.hefner](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/alexander.hefner/32/111_2.png) [@alexander.hefner](https://community.br-automation.com/u/alexander.hefner)\
**Post date:** [February 28, 2024, 8:37pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/8 "2024-02-28T20:37:43Z")

</div>

You have to provide also a result buffer for the text when calling ArTextSysGetText, using the elements .TextBufferSize and .TextBuffer of the function block interface.

Let’s assume your text to read has a maximum length of 128 byte, then you need a string[128] for result, so declare the string variable, for example “myResultString”, and add into your function block call also

```iecst
TextBuffer := ADR(myResultString), TextBufferSize := SIZEOF(myResultString)

```

Best regards!

---

<div class="post-metadata">

**Author:** ![Jack\_Lin2](https://avatars.discourse-cdn.com/v4/letter/j/FF8800/32.png) [@Jack\_Lin2](https://community.br-automation.com/u/Jack_Lin2)\
**Post date:** [February 28, 2024, 9:08pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/9 "2024-02-28T21:08:42Z")

</div>

It finally worked, thanks Alexander! Surprisingly, I didn’t need httpUtf8ToWString() to do this, but its working so I won’t question it.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/brcommunity/original/1X/a202d64f0f03e22a662ed33fbbca6879f1efb794.jpeg) [@system](https://community.br-automation.com/u/system)\
**Post date:** [April 13, 2024, 7:00pm UTC](https://community.br-automation.com/t/reading-and-writing-texts-to-string-variables/2378/10 "2024-04-13T19:00:44Z")

</div>


