Unlike previous Visual Basic versions, under VB.NET you can’t use the Len function to calculate the length of a Structure or a class. However, it is easy to get this information with the SizeOf static method of the System.Runtime.InteropServices.Mashal class, as in:
Imports System.Runtime.InteropServicesModule Module1 ' Notice that this structure contains 2 padding bytes between ' the first two elements Structure MyStruct Public el1 As Short Public el2 As Integer Public el3 As String End Structure Sub Main(ByVal args() As String) Dim struct As mystruct Console.WriteLine(Marshal.SizeOf(struct)) ' => 12 End SubEnd Module