Page 130 - Open Soource Technologies 304.indd
P. 130

Event Driven Programming



                          6.1 Structure
                          Some of the data types we have worked with so far are Double, Integer, String, and Boolean.
                          In previous versions of Visual Basic a Structure was called a user-defined type (UDT). Three pieces
                          of related information about colleges are “name,” “state,” and “year founded.” A  Structure  type
                          capable of holding this data is defined by the following block of statements located in the
                          Declarations section of the Code window.
                                 College
                            Dim name As String
                            Dim state As String
                            Dim yearFounded As Integer
                          End
                          Each of the three subvariables of the  Structure  type is called a member. A  Structure  variable of
                          the type College is declared by a statement such as Dim college1 As College
                          Each member is accessed by giving the name of the Structure variable and the member, separated
                          by a period. For instance, the three members of the  Structure  variable college1 are accessed as
                          college1.name, college1.state, an college1.yearFounded. In general, a  Structure  type is defined by
                          a Structure  block of the form
                           StructureType
                           Dim memberName1 As MemberType1
                           Dim membername2 As MemberType2
                           .
                           .
                          End
                          where StructureType is the name of the user-defined data type; memberName1,
                          memberName2,..., are the names of the members of the Structure; and MemberType1,
                          MemberType2,..., are the corresponding member types, such as String, Integer, Double, or
                          Boolean.
                          A Structure  variable, structureVar, is declared to be of the user-defined type by a statement of
                          the form Dim structureVar As StructureType.


                                         Subvariables of the Structure type is called a member.



                                         1: The following program stores information about two colleges into  Structure
                                         variables of type College and uses the variables to determine which college
                                         is older. Note: In the third line of the btnOlder_Click event procedure, all the
                                         member values of college1 are assigned simultaneously to collegeOlder.
















                          124                    LOVELY PROFESSIONAL UNIVERSITY
   125   126   127   128   129   130   131   132   133   134   135