title: Is there a way to use default arguments that are the result of a function call in VB.NET?
body: <p>I have a whole slew of database access functions which assume a particular connection string.  Within my application I call</p>
  
  <pre><code>myList = DB_MyTable.GetTableItems()
  </code></pre>
  
  <p>and within <code>GetTableItems()</code> I have something like</p>
  
  <pre><code>Dim connection As SqlConnection = MyDB.GetConnection
  </code></pre>
  
  <p>So the connection string is in one place in the code, and I call a method to get it.</p>
  
  <p>What I'm running into now is I want to reuse the same database functions, but with a different connection string.  I can rewrite all of the functions like <code>DB_MyTable.GetTableItems()</code> easily because they're generated from a script, but within the main application code I'll need to take care of every function call that now needs to know what connection string I want to use.</p>
  
  <p>I tried changing the arguments to <code>GetTableItems()</code> like this:</p>
  
  <pre><code>Public Shared Function GetTableItems(Optional ByVal useThisString as String = MyDB.GetConnection) As List(Of MyItems)
  </code></pre>
  
  <p>in hopes of being able to pass in, by default, the string I'm already using in most of the code, but I got an error saying that the default value had to be a constant expression.  This would mean peppering a specific connection string everywhere, which I don't want to do.</p>
  
  <p>Is there a way to accomplish what I'm after, or do I need to make the connection string a required argument and change all of the calls in my application to match the new signature?</p>
  
  <p>Thanks as always!</p>