Practical Programming COMP153-08S Lecture 1: Starting to program.

12
Practical Programming COMP153-08S Lecture 1: Starting to program

Transcript of Practical Programming COMP153-08S Lecture 1: Starting to program.

Practical ProgrammingCOMP153-08S

Lecture 1: Starting to program

Computers

• Central Processing Unit (CPU)– Pentium IV – 3GH (billion / sec)

• Main Memory (RAM)– 512MB (512 books, 512 minutes music)– Holds running programs and their data

• Disk (Hard Drive)– 80GB (80 movies)– Long term storage (with care)

Software (Programs)

• Operating system– The most complex thing ever built

by the human mind– Interacts with you – interprets mouse

clicks, etc– Keeps track of files– Allows several programs to run at the

same time

Programming

• Don’t write individual computer instructions

• Use development environment

• Much is written for us

• We use libraries of useful behaviour and appearance and functionality

Programming Can Be

• Fun and creative

• Demanding– Often meticulous detail required

• Error prone– Very hard to get things just right

• Interacts interestingly with our personalities

Visual Basic (VB)

• Concepts: Control Property Event

• A whole program is quite large. Usually we don’t even look at it, let alone write it ourselves.

• We write ‘event’ handlers – sets of instructions (subroutines) to be run when something happens

Public Class Form1 Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New() MyBase.New()

'This call is required by the Windows Form Designer. InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub

'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents One As System.Windows.Forms.Button Friend WithEvents Two As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.One = New System.Windows.Forms.Button Me.Two = New System.Windows.Forms.Button Me.SuspendLayout() ' 'One ' Me.One.Location = New System.Drawing.Point(64, 64) Me.One.Name = "One" Me.One.Size = New System.Drawing.Size(120, 32) Me.One.TabIndex = 0 Me.One.Text = "I am called One" '

'Two ' Me.Two.Location = New System.Drawing.Point(64, 120) Me.Two.Name = "Two" Me.Two.Size = New System.Drawing.Size(112, 64) Me.Two.TabIndex = 1 Me.Two.Text = "My name is two" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.Two) Me.Controls.Add(Me.One) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False)

End Sub

#End Region

Private Sub One_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles One.Click

Two.Text = "I've been changed" Two.Width = 200 End SubEnd Class

What we see/What we write

Public Class Form1 Inherits System.Windows.Forms.Form

. . . . Hidden lines of program

Private Sub One_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles One.Click

Two.Text = "I've been changed" Two.Width = 200 End Sub

End Class

Subroutines

Private Sub Albert()

instructions

End Sub

• Sub is short for Subroutine

• Group of instructions with a name

Assignment statement

• Something = some expression– Something: a property of a control

• Written controlname . propertyname

– Some expression allows arithmetic and parenthesis

• Button2.Width = 400

• Button2.Width = (900 + 20) / 2

THE END