You are on page 1of 8

2/15/2012

Lecture 13: Programming Concepts

Introduction to Computer
Programming for Engineering

Lecture 13: Programming Concepts

PROGRAMMING
STATEMENTS

1
2/15/2012

Programming Statements

 A programming statement
is a complete instruction.

Programming Statements

Programming Statements
may/can contain:
• Keywords
• Operators
• Variables
• Constants
• Expressions

2
2/15/2012

Programming Statement Categories

Declaration Statements

Assignment Statements

Executable Statements

Lecture 13: Programming Concepts

DECLARATION
STATEMENTS

3
2/15/2012

Declaration Statements

 You use declaration statements to


name and define procedures,
variables, arrays, and constants.

Declaration Statements

 When you declare a procedure, variable,


or constant, you also:

◦ define its scope, depending on where you


place the declaration, and

◦ what keywords you use to declare it.

4
2/15/2012

Declaration Statements - Example

Sub ApplyFormat()

Const Pi As Integer = 3.1416

Dim myCell As Range

' More statements

End Sub

Lecture 13: Programming Concepts

ASSIGNMENT
STATEMENTS

5
2/15/2012

Assignment Statements

 Assignment statements assign a value


or expression to a variable or constant.

 Assignment statements always include an


equal sign (=).

Assignment Statements - Example


Sub MyNameIsWhat()
Dim MyName As String

MyName = " Slim Shady"

MsgBox " My name is " & MyName

End Sub

6
2/15/2012

Lecture 13: Programming Concepts

EXECUTABLE
STATEMENTS

Executable Statements

 An executable statement initiates


action.

 It can execute a method or function, and


it can loop or branch through blocks of
code.

7
2/15/2012

Executable Statements

 Executable statements often contain


mathematical or conditional operators.

Executable Statements - Example


Sub ApplyFormat()

Const limit As Integer = 33

For Each c In Worksheets("Sheet1").Range("MyRange").Cells


If c.Value > limit Then
With c.Font
.Bold = True
.Italic = True
End With
End If
Next c

MsgBox "All done!"

End Sub

You might also like