title: Converting Fixed length statement from VB6 to VB.Net
body: <p>We perform a protocol based data sending to device where the device requires a formatted data packets.</p>
  
  <p>the sample packet data is <code>XXFSXXXFSXXXXXXXFSXXXXXX</code>. The <code>X</code> mentioned is the max length size of each string. if data is less than string max length it should be filled with NULL character like <code>..11FS123FS1234XXXX</code> (the remaining X will be filled with NULL).</p>
  
  <p>I am just trying to convert one of VB6 function to VB.Net and below is the converted statement where i am facing issue  </p>
  
  <pre><code>Option Strict Off
  Option Explicit On
  Imports Microsoft.VisualBasic.Compatibility.VB6
  Imports System
  Imports System.Runtime.InteropServices
  Module FunctionCmd_Msg
  
      Public FunCommand_Msg As Fun_CommandMessage = Fun_CommandMessage.CreateInstance()
      'Function Command Message
      &lt;StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)&gt; _ _
      Public Structure Fun_CommandMessage
          &lt;VBFixedString(1)&gt; Public one As String
          &lt;VBFixedString(1)&gt; Public two As String
          &lt;VBFixedString(3)&gt; Public three As String
          Dim five As String
          &lt;VBFixedString(8)&gt; Public four As String
          Public Shared Function CreateInstance() As Fun_CommandMessage
              Dim result As New Fun_CommandMessage
              result.one = String.Empty
              result.two = String.Empty
              result.three = String.Empty
              result.four = String.Empty
              result.five = String.Empty
          End Function
      End Structure
  End Module
  </code></pre>
  
  <p>assuming:</p>
  
  <pre><code>one = "1"
  two = "1"
  three = "123"
  four = "5678"           
  five = "testing"
  FS = character (field separator)
  </code></pre>
  
  <p>on concatenating the strings i need a fixed length string such like this:</p>
  
  <pre><code>one &amp; two &amp; FS &amp; three &amp; FS &amp; five &amp; FS &amp; four
  </code></pre>
  
  <p>output: since four is a fixed length string of 8 length remaining 4 characters should be filled with null as below      </p>
  
  <pre><code>11 FS 123 FS testing FS 5678XXXX
  </code></pre>