Update User Variable from .net

Hi, I have a user variable and I want to update that from c#. But i don’t know how to do that.

Hello & Welcome Marc!

User variables are primary defined within the Designer for a special report by the user itself. But you can have access these variables by using the DOM interface and the property UserVariables.

At runtime while printing/exporting you can access the used/loaded project with GetFromParent in the event DefinePrintOptions.

Hi, i have done as you said. But when i export as excel i can see the user variable value same as old.
My code

  private void LL_DefinePrintOptions(object sender, EventArgs e)
  {
      // Create new DOM project of type LlProject.List
      ProjectList proj = new ProjectList(LL);

      // No proj.Open() is required. Instead the project of the component is used
      proj.GetFromParent();

      // iterate all user variables
      
      foreach (UserVariable userVariable in proj.UserVariables)
      {
          if (userVariable.Name== "@FontSize")
          {
              userVariable.Contents = "11";
          }else if  (userVariable.Name == "@HeaderFontSize")
          {
              userVariable.Contents = "11";

          }
      }
      proj.Save();
      
  }


In the Designer, you won’t observe any changes because the project is modified dynamically during printing. Have you verified that the event handler is triggered and that the user variables are accurately identified?

Hi Yes. I have set breakpoint. And it changed perfectly. but when it open the designer there has no changes of those user variables.

As I said, the change is just temporary in memory and cannot be observed in the designer. If you want to change the project itself, you need to open it via Open instead of GetFromParent before calling the Designer, then do your modifications and Save, then Close the project.

what about if i want to export?

Either change the project on the fly or beforehand, whatever is more practical.

is there any example code of that?

Actually this will be used by customer. They don’t have experience with it. What i want is to change table font size before the export to excel only. On the designer we can keep as it is. So, i used a variable there. And want to change that variable from the .net before export.

Why not using LL.Variables.Add("FontSize",11) and set the uset variables value to FontSize then? Or use the variable directly where appropriate?

ok thanks let me check

Right in this thread :slight_smile:

HI, I have tried. but the variable not showing at font formula in designer

Check what happens if you set LL.AddVarsToFields to true.

Hi after i added @FontSize in the code then worked.
so new code looks like this:

   LL.Variables.Add("@FontSize", 7);