title: Can’t group my text into blocks of 5 letters in VB2010
body: <p>I'm relatively new to VB and I am trying to develop a simple Encryption Program.  I have most of the code nailed but to make my encryption program even better I want to group my text into blocks of 5 letters.  However, my Function to do this doesn’t work. I suspect something is wrong with my IFs or loop.</p>
  
  <pre><code>    Function ExtendedEncrypt(ByVal MessageText As String, ByVal txtOffset As Integer) As String
              Dim StringLength As String
      Dim CharToEncrypt As Char
      Dim EncryptedText As String
      Dim CharAscNumber As Integer
      Dim CipherText As String
      Dim Counter As Integer
      StringLength = Len(MessageText)
      CipherText = ""
      For Counter = 1 To StringLength
          CharToEncrypt = Mid(MessageText, Counter, 1)
          If CharToEncrypt = " " Then
              EncryptedText = ""
          Else : CharAscNumber = Asc(CharToEncrypt)
              CharAscNumber = CharAscNumber + txtOffset
              If CharAscNumber &gt; 126 Then
                  CharAscNumber = CharAscNumber - 94
              End If
              EncryptedText = Chr(CharAscNumber)
              If Counter Mod 5 = 1 And Counter &gt; 1 Then EncryptedText = EncryptedText &amp; " "
          End If
          CipherText = CipherText &amp; EncryptedText
          txtEncrypted.Text = CipherText
      Next
      Return CipherText
  End Function
  </code></pre>