Structures
Structures are the least understood of the three forms of objects. If we were talking about "animals" instead of "objects", the structure would be an Aardvark.
The big difference between a structure and a class is that a structure is a value type and a class is a reference type.
What does that mean? I'm so glad you asked.
A value type is an object that is stored directly in memory. An Integer is a good example of a value type. If you declared an Integer in your program like this ...
Dim myInt as Integer = 10
... and you checked the memory location stored in myInt, you would find the value 10. You also see this described as "being allocated on the stack".
The stack and the heap are simply different ways of managing the use of computer memory.
A reference type is an object where the location of the object is stored in memory. So finding a value for a reference type is always a two step lookup. A String is a good example of a reference type. If you declared a String like this ...
Dim myString as String = "This is myString"
... and you checked the memory location stored in myString, you would find another memory location (called a pointer - this way of doing things is the very heart of C style languages). You would have to go to that location to find the value "This is myString". This is often called "being allocated on the heap". The stack and the heap
Some authors say that value types aren't even objects and only reference types can be objects. It's certainly true that the sophisticated object characteristics like inheritance and encapsulation are only possible with reference types. But we started this whole article by saying that there were three forms for objects so I have to accept that structures are some sort of object, even if they're non-standard objects.
The programming origins of structures go back to file-oriented languages like Cobol. In those languages, data was normally processed as sequential flat files. The "fields" in a record from the file were described by a "data definition" section (sometimes called a "record layout" or a "copybook"). So, if a record from the file contained:
1234567890ABCDEF9876
The only way you would know that "1234567890" was a phone number, "ABCDEF" was an ID and 9876 was $98.76 was through the data definition. Structures help you accomplish this in VB.NET.
Structure Structure1
<VBFixedString(10)> Dim myPhone As String
<VBFixedString(6)> Dim myID As String
<VBFixedString(4)> Dim myAmount As String
End Structure
Because a String is a reference type, it's necessary to keep the length the same with the VBFixedString attribute for fixed length records. You can find an extended explanation of this attribute and attributes in general in the article Attributes in VB .NET.
Although structures are non-standard objects, they do have a lot of capability in VB.NET. You can code methods, properties, and even events, and event handlers in structures, but you can also use more simplified code and because they're value types, processing can be faster. For example, you could recode the structure above like this:
Structure Structure1
<VBFixedString(10)> Dim myPhone As String
<VBFixedString(6)> Dim myID As String
<VBFixedString(4)> Dim myAmount As String
Sub mySub()
MsgBox("This is the value of myPhone: " & myPhone)
End Sub
End Structure
And use it like this:
Dim myStruct As Structure1
myStruct.myPhone = "7894560123"
myStruct.mySub()
It's worth your time to play around with structures a bit and learn what they can do. They're one of the odd corners of VB.NET that can be a magic bullet when you need it.

