0
Public Structure TMProduct
        <VBFixedString(25)> Public productline As String
        <VBFixedString(25)> Public hinban As String
        <VBFixedString(25)> Public shortcode As String
        <VBFixedString(25)> Public fusible As String
        Public nutcount As Integer
        <VBFixedArray(11)> Public nuts() As Integer
        <VBFixedString(512), VBFixedArray(11)> Public tips() As String
End Structure

in VB6 the length of this structure is "12514"
and I used LenB function.

but LenB is not supported in VB.Net
I've reading on some other forums that they use Marshal.SizeOf
but in my case it doesn't do as LenB

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by aldeene
0

In order to compute the length of a structure mostly you'll need to create a default (dummy) instance of it an then compute their size.

Maybe this code, from Jim Mischel, is valid for you:

public static int GetSize<T>()
{
  Type tt = typeof(T);
  int size;
  if (tt.IsValueType)
  {
    if (tt.IsGenericType)
    {
      Console.WriteLine("{0} is a generic value type", tt.Name);
      var t = default(T);
      size = Marshal.SizeOf(t);
    }
    else
    {
      Console.WriteLine("{0} is a value type", tt.Name);
      size = Marshal.SizeOf(tt);
    }
  }
  else
  {
    Console.WriteLine("{0} is a reference type", tt.Name);
    size = IntPtr.Size;
  }
  Console.WriteLine("Size = {0}", size);
  return size;
}

Then call it using int structsize = GetSize(TMProduct) The Console output is just for debugging purposes an can be easely removed :)

Hope this helps

Votes + Comments
nothing personal, just .cs code in .vb forum.
0

didn't tried it but thanks, I didn't use structures anymore coz i'm not very familiar with it and fileput.. anyway thanks again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.