title: How to access variables in Windows Workflow in VB expressions constructed at runtime
body: <p>I hope I'm not being misguided in trying to do this, but I'd like to set the VB expression for an InArgument in Windows Workflow at runtime and have it access variables that are currently in scope.</p>
  
  <p>In particular, I'd like to change the following bit of example code to say <code>new VisualBasicValue&lt;string&gt;("String.Format(\"Hello {0}\", FirstName)</code> - that is, I'd like to stop specifying the explicit string "World" and start passing in a name to the workflow from <code>Main</code>. I add a new InArgument called <code>FirstName</code> to the workflow itself, and then try and access it as above, but it doesn't work - I'm guessing because it doesn't know what <code>FirstName</code> is referring to at the point at which it compiles the expression. Please do you know of an alternative way to accomplish the same goal?</p>
  
  <p>(The context for this problem is that I'm writing code to run different types of calculation. A calculation takes a string parameter that contains a VB expression that must be run to get some data from one of a variety of different locations. I want to specify the VB expression for each different calculation type in a .config file, then evaluate those expressions "on-the-fly" at runtime when it becomes necessary to run the various different calculations.)</p>
  
  <pre><code>using System.Activities;
  using Microsoft.VisualBasic.Activities;
  
  namespace SMG_RuntimeExpressionTest
  {
      class Program
      {
          static void Main(string[] args)
          {
              var wf = new Workflow();
              wf.Text = new VisualBasicValue&lt;string&gt;("String.Format(\"Hello {0}\", \"World\")");
              WorkflowInvoker.Invoke(wf);
          }
      }
  }
  </code></pre>