RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB7
Expertise: Intermediate
Jul 6, 2002



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Determine the size of a structure

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.InteropServices

Module 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 Sub
End Module

Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date