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

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

Jan 02, 2016

Download

Documents

Rafe Cain
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Practical Programming COMP153-08S Lecture 1: Starting to program.

Practical ProgrammingCOMP153-08S

Lecture 1: Starting to program

Page 2: Practical Programming COMP153-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)

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

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

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

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

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

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

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

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

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

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" '

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

'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

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

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

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

Subroutines

Private Sub Albert()

instructions

End Sub

• Sub is short for Subroutine

• Group of instructions with a name

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

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

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

THE END