Navigation bar
  Start Previous page
 89 of 158 
Next page End  

83
Structures may be used in Alias and Based variable definitions.  However, in these cases the structures
may not contain members that are any of the string types.  Structures may be passed to subroutines and
functions either by reference or by value.  If a structure is passed by value, the structure will be read-only
within the procedure.
A variable that is a structure may be assigned to another variable that is the same type of structure using
the standard assignment operator as long as the structure does not contain any members that have the
allocated string type.  In contrast, assignment of structures with members that are fixed-length or
bounded strings is supported.  Likewise, two variables that are the same type of structure may be
compared for equality or inequality using the standard comparison operators, = and <>.  The
equality/inequality test is implemented using a byte-by-byte comparison of the content of two structures. 
If one or more members of the structure are the BoundedString type, the byte-by-byte comparision may
result in a False value even though the strings are identical.  This is because the currently-unused portion
of the string store may contain byte values that are different between the two instances being compared. 
Similarly, comparison of structures containing allocated strings, while allowed, is not recommended
because of the likelihood of resulting in false negatives. 
Structures may contain members that are sub-byte types, Bit and Nibble.  Members that are Bit type
will be aligned on the next available bit boundary and those that are Nibble type will be aligned on the
next available nibble boundary.  If a member that is not a sub-byte type follows a sub-byte type member,
that non-sub-byte member will be aligned on the next available byte boundary.  Depending on how you
define your structure, this may result in “holes” in the structure layout representing unused bits.  The
unused bits are generally of no consequence but it is important to note that these “holes” may interfere
with the equality/inequality test for structures that are not initialized because the unused bits will have an
indeterminate value.  You can avoid this potential problem by performing a block initialization on locally
defined structures.
Example
' this structure contains a "hole", unused bits following the ab member
Structure foo
Dim b as Byte
Dim ab(1 to 4) as Bit
Dim b2 as Byte
End Structure
Sub Main()
' this structure is not automatically initialized
Dim bar as foo
' this call zeroes out the entire structure
Call MemSet(bar.DataAddress, SizeOf(bar), 0)
' other code follows
End Sub
Another method of creating a user-defined type, compatible with VB6, is also supported.  The syntax for a
Type definition is:
[Public | Private] Type <name>
<member-definition>
...
End Type
In this case, the <member-definition> is the same as for defining a member of a Structure except
that the visibility attribute (Public, Private, or Dim) is not allowed.  The visibility of each member will
be the same as the visibility of the Type itself.
Previous page Top Next page