How to access document variables from basic macro?

I find no single way in any documentation to archieve this:

A text document in Writer contains a contract. It also contains a basic macro with dialog where this contract can be configured. It asks for names, values, dates, and provides list boxes with predefined options to choose from. After hitting OK, the macro will
a) put the names into predefined placeholders (my way was to add a field that displays a variable)
b) switch on and off several hidden paragraphs (here, they also react on well-defined variable conditions).

So, in short, I want to access that “document variables” from my macro.
Googeling anything that should make sense led to massive amounts of useless information, also because there is no real way to distinguish variables that are defined by Insert → Fields → More Fields → Variables → Set Variable and classic variables like “Public name as String”.

I tried to record a macro where I manually edit a set-variable-field and hoped it would show me how to access it and put in a new value, but that resulting macro didn’t reflect this step.

Hi

The UpdateVar.odt attached includes:

  • Variable MyVarBool (Boolean format)
  • Variable MyVarText (Text format)
  • A hidden conditional section (Hide with condition: MyVarBool)

The program below:

  • Checks for the variable, if exists…
  • Puts the current time in the variable MyVarText
  • Switches the MyVarBool variable true / false

The section is displayed or not based on the contents of the variable MyVarBool (see FormatSection)

Sub UpdateVariable
dim oDoc as object, oVar as object

oDoc =ThisComponent

if oDoc.getTextFieldMasters.hasByName("com.sun.star.text.fieldmaster.SetExpression.MyVarText") then
	oVar = oDoc.getTextFieldMasters.getByName("com.sun.star.text.fieldmaster.SetExpression.MyVarText")
	oVar.DependentTextFields(0).content = time
else
	msgbox "MyVarText not found"
end if

if oDoc.getTextFieldMasters.hasByName("com.sun.star.text.fieldmaster.SetExpression.MyVarBool") then
	oVar = oDoc.getTextFieldMasters.getByName("com.sun.star.text.fieldmaster.SetExpression.MyVarBool")	
	with oVar.DependentTextFields(0)
		if .Value = 0 then 
			.content = "TRUE"
		else
			.content = "FALSE"
		end if	
	end with	
else
	msgbox "MyVarBool not found"
end if

oDoc.textFields.refresh

end sub

Regards

I thank you very much for your explaination and put it to the test if it’s a viable solution. Sadly, it’s so clumpsy solving my problem on this way, that I refused using LO but tried HTML5 and PhantomJS, where I have full DOM / Document access. That kind of features seem to be missing here, maybe for the sake to be as much like M$ as possible. Thanks a lot, though!