Your SlideShare is downloading. ×
  • Like
  • Save
Pemrograman komputer  7 (prosedur)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Pemrograman komputer 7 (prosedur)

  • 682 views
Published

unj fmipa-fisika

unj fmipa-fisika

Published in Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
682
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Pemrograman Komputer Pertemuan 07 Procedures Bambang Heru Iswanto, Dr.rer.nat M.Si
    • Jurusan Fisika
    • Fakultas Matematika dan Ilmu Pengetahuan Alam
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 2. Learning Outcomes
    • Pada akhir pertemuan ini, diharapkan mahasiswa
    • akan mampu :
    • Menerapkan penggunaan prosedur
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 3. Outline Materi
    • Procedures
    • Needed for Procedures
    • Parameter Passing
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 4. Procedures
    • In program design, we break the overall task into sub tasks. These subtasks are implemented using procedures. Each procedure should carry out one sub task.
    • A procedure is simply a way of performing  code 'out of line'. When a program encounters a call to a procedure, it suspends its current path through the code statements and passes control to a separate chuck of code. When this separate chuck has been executed, control returns to the statement immediately following the call:
    • Private Sub cmdButton_Click()
    • Call aProcedure
    • End Sub
    Private Sub aProcedure … End Sub 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 5. Procedures
    • All procedures consist of a header that indicates the procedure name and any information that it requires
    • Body that performs the task
    • If a procedure is to be used by a number of different forms it should be declared as Public within the code module otherwise it should be declared as Private in the general declaration section of the form.
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 6. Needed for Procedures
    • A simplification of the program structure
    • Reduction in the amount of code that is repeated
    • Ability to focus on what needs to be done rather than how it is to be achieved
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 7. Parameter Passing
    • Procedures are not very useful though unless they can communicate data
    • Data passed between procedures are called parameters
    • Parameters can be sent to the procedure for use within it, e.g. calculations
    • Results from the procedure can be sent back by the procedure to the calling program
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 8. Parameter Passing - Example Main keyInput num1 keyInput num2 IF num1 < num2 THEN Call Swap(num1, num2) ENDIF conOutput “Largest”, num1 Swap (num1, num2) temp = num1 num1 = num2 num2 = temp The variables num1 and num2 are passed to the procedure Swap for exchanging. After the procedure, the largest number is in num1 . 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 9. Parameter Passing – VB Solution
    • Private Sub Form_Click()
    • num1 = InputBox(&quot;enter number 1&quot;)
    • num2 = InputBox(&quot;Enter number 2&quot;)
    • If num1 < num2 Then
    • Call Swap(num1, num2) ‘call to the procedure
    • End If
    • MsgBox &quot;Largest &quot; & num1
    • End Sub
    • Private Sub Swap(num1 As Integer, num2 As Integer)
    • Dim temp As Integer ‘temp is a var. local to Swap
    • temp = num1
    • num1 = num2
    • num2 = temp
    • End Sub
    Parameter list for procedure 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 10. Parameter Passing - Rules
    • Values are copied into the parameters The order of parameters declared in the procedure MUST match the order in which they were called
    • The data types must match. E.g. 1 is OK, e.g. 2 is not and will crash program!
    • E.g. 1 Call Swap(num1, num2)
    • Private Sub Swap(num1 As Integer, num2 As Integer)
    • E.g. 2 Call AnyProc(myName, myAge)
    • Private Sub AnyProc(myAgeAs Integer, myName As String)
    01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  • 11. TERIMA KASIH 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |