title: Use a variable outside of an if/case statement vb.net
body: <p>I am working in vb.net visual studio express with an sql back end. I have a very long few SQL commands and I need to change a section of the sql command dependent on a number being generated from a textbox. I can either re-write 150 lines of code multiple times to handle the situation or somehow carry a variable down to it outside of an IF statement. Here is what I mean.</p>
  
  <pre><code>If textbox.text = "5" then
  
      Dim string = "Some text to be used in an sql statement"
  
  Elseif textbox.text = "6" then
  
      Dim string = "Some other text to be used in an sql statement"
  
  End if (Please note there are more than 2 examples)
  
  Using comm1 as new sqlcommand ("blah blah blah " &amp; String &amp; " blah blah blah", conn1)
  </code></pre>
  
  <p>So considering the "&amp; String &amp; is outside of my if statement it means that it is not recognized being outside of the if statement. However I dont want to re-write 150 lines of code multiple times so I need a way to carry that string function down to it. Can i do this with the if statement or a case statement?</p>