title: How to generate a receipt number
body: <p>On Stack&nbsp;Overflow, I found the question <em><a href="https://stackoverflow.com/questions/1941886/generate-a-receipt-number-in-this-range">Generate a receipt number in this range</a></em>.</p>
  
  <p>In answers (from Adam Maras) I find this code (very interesting for me):</p>
  
  <pre><code>Private Const FirstReceiptNumber As String = "GA00000"
  
  Public Function GenerateReceiptNumber(ByVal lastNumber As String) As String
  
      If lastNumber.Length &lt;&gt; 7 Then
          Throw New ArgumentException("Incorrect length", "lastNumber")
      End If
  
      If lastNumber.StartsWith("G") = False Then
          Throw New ArgumentException("Incorrect start character", "lastNumber")
      End If
  
      Dim letterPortion As Char = lastNumber.Chars(1)
  
      If letterPortion &lt; "A"c Or letterPortion &gt; "Z"c Then
          Throw New ArgumentException("Non-letter second character", "lastNumber")
      End If
  
      If letterPortion = "I"c Or letterPortion = "O"c Then
          Throw New ArgumentException("Invalid second character", "lastNumber")
      End If
  
      Dim numericPortionString As String = lastNumber.Substring(2)
      Dim numericPortion As Integer
  
      If Integer.TryParse(numericPortionString, numericPortion) = False Then
          Throw New ArgumentException("Invalid numeric portion", "lastNumber")
      End If
  
      If numericPortion = 99999 Then
          If letterPortion = "Z"c Then
              Throw New ArgumentException("No more receipt numbers possible", "lastNumber")
          End If
  
          numericPortion = 0
          letterPortion = letterPortion + Chr(1)
  
          If letterPortion = "I"c Or letterPortion = "O"c Then
              letterPortion = letterPortion + Chr(1)
          End If
      Else
          numericPortion = numericPortion + 1
      End If
  
      Return String.Format("G{0}{1:00000}", letterPortion, numericPortion)
  End Function
  </code></pre>
  
  <p>I paste it to a Visual Studio 2010 form, and I try to see what happen on <code>Form_Load</code>.</p>
  
  <pre><code>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      TextBox1.Text = GenerateReceiptNumber() '&lt;--HERE IS THE ERROR
  End Sub
  </code></pre>
  
  <p>But show me error in <code>GenerateReceiptNumber()</code>.</p>
  
  <p>How do I use that code to give me a receipt number in <code>TextBox1</code> when I open this form?</p>
  
  <p>The receipt number must be +1 next time with <code>Form_Load</code>.</p>