html5-img
1 / 5

Structures and Arrays

Structures and Arrays. Collections of Variables. Arrays. An array is a collection of variables All with same name All with same data type Accessed by integer index Example Dim grades(20) as integer creates an array of 21 integer variables : grades(0) . . . grades(20) Example

jerry-king
Télécharger la présentation

Structures and Arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structures and Arrays Collections of Variables

  2. Arrays • An array is a collection of variables • All with same name • All with same data type • Accessed by integer index • Example • Dim grades(20) as integer creates an array of 21 integer variables : • grades(0) . . . grades(20) • Example • Dim grades() as integer defines grades as dynamic array • Redim preserve grades(numGrades) adds a variable grades(numGrades) to collection without changing the first numGrades -1

  3. Structures • A structure is a Named collection of variables with • Different names • Different data types • Accessed by <StructureVariable>.<VariableName> where <StructureVariable> has been defined as type with Structure name. • A structure defines a new data type • Example • 'structure - collection of customer attributes • PublicStructure Customer • Dim Name AsString • Dim Phone AsString • Dim Address AsString • Dim ID AsInteger • EndStructure

  4. Arrays of Structures Public NumberCustomers AsInteger 'dynamic array of customers Public Customers() As Customer • NumberCustomers += 1 • Dim c As Customer • With c • .Name = tbCustomerName.Text • .Phone = tbCustomerPhone.Text • .Address = tbCustomerAddress.Text • .ID = NumberCustomers • tbCustomerID.Text = .ID • EndWith • ReDimPreserve Customers(NumberCustomers) • Customers(NumberCustomers) = c

  5. Comma Separated Strings • Let txtLine be a string read in from a text file • txtLine = “Brown,32 W Spring,372-3662 • The Split method may be used to separate the fields of txtLine : • Dim fields() as string • fields = string.split(“,”c)

More Related