title: How do I keep a variable value across subs?
body: <p>I have some code made by the IDE that makes the textboxes as Subs. I need to retain the value of the variable 'printString' from one Sub to another. My searching seems to indicate that the first sub needs to be turned into a function, but when I do that it breaks. </p>
  
  <pre><code>    Private Sub txtSerialNumber_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSerialNumber1.Leave
      'condition the scanned serial number
      Dim serialNumber As String = txtSerialNumber1.Text
      serialNumber = serialNumber.ToUpper()
      serialNumber = serialNumber.Trim()
      txtSerialNumber2.Focus()
      'replace tokens
      'read the label file into a string variable
      Dim printString As String = My.Resources.Fuel_Cell_Label
      'read the top position into a variable
      Dim topPosition As String = My.Settings.prntLabelTop
      'read the left position into a variable
      Dim leftPosition As String = My.Settings.prntLabelLeft
      'replace the tokens with values
      printString = printString.Replace("[[Top]]", topPosition)
      printString = printString.Replace("[[Left]]", leftPosition)
      printString = printString.Replace("[[serial_1]]", serialNumber)
  End Sub
  
  Private Sub txtSerialNumber2_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSerialNumber2.Leave
      'condition the scanned serial number
      Dim serialNumber2 As String = txtSerialNumber2.Text
      serialNumber2 = serialNumber2.ToUpper()
      serialNumber2 = serialNumber2.Trim()
      'reset the front panel controls
      txtSerialNumber1.Text = ""
      txtSerialNumber2.Text = ""
      txtSerialNumber1.Focus()
      'replace the last token
      printString = printString.Replace("[[serial]]", serialNumber2)
      'print the label string
      Dim Printer As New Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer
      Printer.Print(printString)
      'MessageBox.Show(printString)
  End Sub
  </code></pre>
  
  <p>And yes, I am new to this.</p>
  
  <p>How would I keep that variable value?</p>