Structure PowerPoint PPT Presentation

presentation player overlay
1 / 12
About This Presentation
Transcript and Presenter's Notes

Title: Structure


1
Structure
  • Main function to create records
  • Declared in a module or class
  • For example,

Name of the structure
Public Structure item Public id As
String Public price As Decimal End
Structure
item
Id Price
2
Public products(1) as item products is an
array with 2 records
0
1
products
id price
id price
products(0).id 101 products(0).price
19.99 products(1).id 102 products(1).price
15.05
3
Structure Declaration
Module Module1 Public Structure item
Public id As String Public price As
Decimal End Structure Public products(1)
As item End Module
4
ArrayList
  • A dynamic array (size not fixed) can add and
    remove items from an arrayList, index is
    zero-based.
  • To create an ArrayList
  • Dim Cart as New ArrayList
  • To add an object to the ArrayList
  • Cart.Add(products(1))
  • Cart.Add(products(0))
  • What value does Cart(0).id have?

5
Add an item to Cart and dynamically generate two
labels
Cart.Add(products(0)) add first
item to Cart For I 0 to 1 generate two
labels, one in each iteration Dim Mylabel as
new label create a new label
Me.Controls.Add(mylabel) add the
label to form If I 0 then
Mylabel.left 50 Mylabel.text
cart(0).id display id of the first item
in cart else Mylabel.left 100
Mylabel.text cart(0).price display
price of the first item in cart End if Next
6
ArrayList
  • To remove items
  • Cart.Remove(products(0)) remove an object
  • Cart.RemoveAt(1) remove the second element

Dim myItem As item For Each myItem
In cart If myItem.id 101 Then
cart.Remove(myItem)
Exit For End If Next
7
ArrayList
  • Property Count
  • Property Indexof returns the index of an
    element of arraylist

Index value
Button2 clicked
8
(No Transcript)
9
Create event handlers at runtime
10
Create a new button, which can be clicked
11
AddHandler Statement
General form AddHandler control.event, New
System.EventHandler(AddressOf subXYZ)
It connects control.event to subXYZ, a
pre-written procedure.
Private Sub createNewButton_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click Dim b As New
Button Me.Controls.Add(b) b.Top
150 b.Left 100 b.Tag "101"
AddHandler b.Click, New System.EventHandler(A
ddressOf processNewButtonClick) End Sub
12
AddHandler Statement (continued)
Private Sub processNewButtonClick(ByVal sender
As System.Object, ByVal e As System.EventArgs)
Dim myButton As New Button myButton
CType(sender, Button) Label1.Text
CStr(myButton.Tag) End Sub
Write a Comment
User Comments (0)
About PowerShow.com