title: Trying To Get The Name Of A Variable as a String VB.NET
body: <p>I'm trying to return the name of a variable as a string.</p>
  
  <p>So if the variable is var1, I want to return the string "var1".</p>
  
  <p>Is there any way I can do this?  I heard that Reflection might be in the right direction.</p>
  
  <p>Edit:</p>
  
  <p>I'm essentially trying to make implementation of an organized treeview simpler. 
  I have a method that you give two strings: rootName and subNodeText. The rootName happens to be the name of a variable. The call to this method is from within a with block for this variable. I want the user to be able to call Method(.getVariableAsString, subNodeText) instead of Method("Variable", subNodeText). The reason for wanting to get it programmatically is so that this code can be simply copied and pasted. I don't want to have to tweak it every time the variable is named something abnormal.</p>
  
  <pre><code>Function aFunction()
     Dim variable as Object '&lt;- This isn't always "variable".
     Dim someText as String = "Contents of the node"
  
     With variable '&lt;- Isn't always "variable". Could be "var", "v", "nonsense", etc
        'I want to call this
        Method(.GetName, someText)
        'Not this
        Method("Variable",someText)
  
     End With
  End Function
  </code></pre>