Monday, July 26, 2010

More Coding

'Column Counter 

Dim intXCount As Integer = 1
'Row Center

Dim intYCount As Integer = 1
'start the loop
For intx = 1 To intTotalNumberOfCells
Dim strCellText As String = "x:" & intXCount & "y:" & 
intYCount
'Add a new cell
ThisTableLayoutPanel.RowStyles.Add
(New   RowStyle(SizeType.Percent, 1))
ThisTableLayoutPanel.ColumnStyles.Add

(New ColumnStyle(SizeType.Percent, 1))
'Pet object from the array

Next
'declare a pet object from the array
'at the index of the loop counter - 1

Dim ThisPet As Pet = MyPets(intXCount - 1)

'instantiate a MyPanel object

'& pass through the required pet object

Dim ThisPanel As New MyPanel(ThisPet, strCellText)

'Add the MyPanel control to the

'TableLayoutPanel's control collection

ThisTableLayoutPanel.Controls.Add(ThisPanel)

'reset the coloumn counter (intXCount) to 1 and 
'increment the row counter (intYCount) by 1

If intXCount > intNumberOfColumnsRequired Then

intXCount = 1

intYCount += 1

End If

Coding


Dim intXCount As Integer = 1
Dim intYCount As Integer = 1

For intX =1 To intTotalNumberOfCells

Dim strCellText As String = "x : 1"& intXCount & "y:1" & intYCount

intXCount +=1

If intXCount > intNumberOfColumnsRequired Then

intXCount =1
intYCount = 1

27/7/2010

Public Class MyPanel

    Inherits Panel

    Private _ThisPet As Pet
    Private _PanelLabel As Label

    Public Sub New(ByVal APet As Pet, ByVal PanelLocation As String)

        _ThisPet = APet
        _PanelLabel = New Label

        'fLUFFY X:1 Y:1

        _PanelLabel.Text = _ThisPet.getPetName & " " 
        &   PanelLocation
        Me.Controls.Add(_PanelLabel)

    End Sub


End Class

27/7/2010 MyPets Array

        
       Dim MyPets(8) As Pet

        MyPets(0) = New Dog("Robbie", 2)
        MyPets(1) = New Dog("Benny", 4)
        MyPets(2) = New Dog("Pippy", 3)
        MyPets(3) = New Dog("Timmy", 5)
        MyPets(4) = New Cat("Princess", 4)
        MyPets(5) = New Cat("Prince", 6)
        MyPets(6) = New Cat("Anna", 10)
        MyPets(7) = New Cat("Crumpet", 13)
        MyPets(8) = New Cat("Muffin", 12)

        Dim intNumberOfRowsRequired As Integer = 3
        Dim intNumberOfColumnsRequired As Integer = 3
        Dim intTotalNumberOfCells As Integer 
        = intNumberOfRowsRequired
      
        'Instantiate an object of the TableLayoutPanel class.
         Dim ThisTableLayoutPanel As New Windows.Forms.TableLayoutPanel

        'set some of its properties
        'set the cell border style

        ThisTableLayoutPanel.CellBorderStyle 
        = ThisTableLayoutPanel.CellBorderStyle

        'set the number of columns

        'set the number of rows

        ThisTableLayoutPanel.RowCount = intNumberOfRowsRequired

        'set the position on the form and the dimensions of
        'the TabelLayoutPanel object

        ThisTableLayoutPanel.SetBounds(0, 0, Me.Width, Me.Height)

         'set how the object will dock to the form

        ThisTableLayoutPanel.Dock = DockStyle.Fill

Design-Time and Run-Time


Design-Time

The toolbox includes controls, when we manually manipulate such controls, taking them straight from the toolbox and using the Properties Pane to set the properties, we are doing this at Design-time. We must place the controls we require on the form ourselves during this time.

Run-Time

While the program is running we can add controls dynamically or programatically. The controls are classes from the VB library.When we want to we can instantiate these objects at any time.

Sunday, July 25, 2010

A Cat is always a Pet but a Pet is not always a Cat

An array of pets:
Dim MyPets (8) As Pet
MyPets (0) = New Dog ()
MyPets (1) = New Cat ()

PublicSubNew (APet As Pet)

Declaring a pet

Dim ThisCat As New Cat
Dim ThisDog As New Dog

Inheritence


Normal Inheritance:

Parent CAN have instances of itself
Dim MyParent As New Parent()

Abstract Class Inheritance:

Parent CANT have instances of itself 
Cannot be declared as above

Concrete: practical application
Abstract: theoretical application


Sunday, July 18, 2010

What is an abstract class?


A class that is designed to provide common state and behavior for it's child classes.

It is not designed to have instances of itself (this type of class cannot be directly instantiated)The children class can be instantiated. 

An example of a class hierarchy where an abstract class would be useful:Office Furniture, children classes would include chair, desk and filing cabinet.