Writer: text-valued variables

Insert>Field>More Fields allows to define variables and set their value.

Built-in help suggests they can have a text value (format code @). It explicitly states that strings in conditions must be bounded by double quotation marks (such as x == "ABC" in page Defining Conditions) which means variables can have non-numeric value.

However, when a non-numeric value is given to a variable, it displays as 0 (zero), even if format code is @. I also tried to enclose the value between double quotation marks to no avail.

Is there an unwritten restriction that Writer variables are exclusively numeric-valued?

Note: an imperfect workaround is to define a custom property with File>Properties. This workaround is imperfect because the property value is constant across the document and cannot be changed to have a different insertion (which is my primary goal). Another workaround is conditional text but it requires using complicated hidden text/paragraph instead of a mere variable in the case of a simple word insertion through this variable.

LO 6.4.5.2, Fedora Linux 32

The type of a variable is defined at the definition time, when you may set its format to text. After that, changing the format to numeric when you edit the field, does not work as expected. That is a problem IMO; but knowing this may allow you to make it working.

Thanks. Apparently the initial format sets an immutable “type”. Maybe doc should be improved about it.

The respective property is .SubType . You can change it by user code.
See Service SetExpression

@Lupp: Danke schön! But I try to avoid resorting to macros whenever I can (I’ve not yet written one, I should learn).

Of course, it’s mostly a good idea to avoid “macros”. However, there are cases where the UI doesn’t offer sufficiently powerful and/or consistent means.

Sub makeVariableFieldTextTypeAndSetString(Optional pString As String)
REM A textfield defining a variable must be the sole selected TextRange.
If IsMissing(pString) Then pString = "Use the context menu now to edit the field!"
tf = ThisComponent.CurrentSelection(0).TextField
tf.SubType = 3 REM String
tf.Input = False
tf.Content = pString
tf.CurrentPresentation = pString
REM I didn't research every thinkable implication!
End Sub