1 / 14

Visual Basic.NET – Flow Control Statement

Visual Basic.NET – Flow Control Statement. Rully Yulian MF MCAD,MCPD,MCT,MVP VB.NET Independent IT Trainer - Application Developer http://www.yulianmf.com rully@yulianmf.com. Overview. Conditional Statement Iteration Statement Jenis-jenis Error Exception Handling.

senwe
Download Presentation

Visual Basic.NET – Flow Control Statement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic.NET – Flow Control Statement Rully Yulian MF MCAD,MCPD,MCT,MVP VB.NET Independent IT Trainer - Application Developer http://www.yulianmf.com rully@yulianmf.com

  2. Overview • Conditional Statement • Iteration Statement • Jenis-jenis Error • Exception Handling

  3. Conditional Statement • Digunakan untuk memproses input yang beragam • Gunakan Conditional Statement untuk pengambilan keputusan bercabang One-way if Either-or Multiple outcome Selection Do you want to buy a guitar? Do you want a silver guitar or a black guitar? A silver guitar, a black guitar with updown tremolo, or a plain tremolo black guitar? What color guitar do you want?

  4. Conditional Statement (If) • If…Then • If Condition Then Statement • If Condition Then Statement End If • If Condition1 Then Statement Else If Condition2 Then Statement Else Statement End If • Gunakan Nested If…Then untuk struktur keputusan yang lebih kompleks

  5. Conditional Statement (Select Case) • Select Case : • Lebih simple dibandingkan dengan If …Then jika digunakan untuk tes sebuah nilai (kasus) • Select Case ValueCase Case nilai1 Statement Case nilai12 Statement Case Else Statement End Select

  6. Iteration Statement • Jenis Iteration Statement For loop While loop Do loop For Each loop

  7. For Loop • Digunakan untuk iterasi dengan jumlah iterasi yang dapat dihitung dengan menggunakan counter • For counter As Integer = 0 To Me.Controls.Count If TypeOf(Me.Controls(counter)) Is TextBox Then Dim txtBox = DirectCast(Me.Controls(0), TextBox) txtBox.ResetText() End If Next

  8. For Each Loop • Digunakan untuk iterasi item yang terdapat didalam sebuah Object Collection • Dim arrWarna() As String = {“Biru”, ”Hijau”, “Merah”} For Each warna As String In arrWarna MsgBox(warna) Next

  9. While Loop • Digunakan sebagai loop untuk zero or more times looping selama statementnya bernilai true • Dim maxVal = 10 Dim intNum = 0 While intNum < maxVal intNum += 1 MsgBox (intNum) End While

  10. Do Loop • Digunakan sebagai loop untuk one time looping atau lebih selama statementnya bernilai true • Dim maxVal = 10 Dim intNum = 0 Do intNum += 1 MsgBox (intNum) Loop While intNum < maxVal

  11. Skip and Exit Iteration • Gunakan perintah Exit untuk keluar dari iterasi For counter As Integer = 0 To 10 … Exit For … Next • Gunakan perintah Continue For untuk skip current looping ke counter berikutnya For counter As Integer = 0 To 10 … Continue For … Next

  12. Jenis-jenis Error • Syntax Error • Paling mudah diidentifikasi • Compile Time Checking • Run Time Error • Terjadi ketika aplikasi dijalankan • Jika memungkinkan dapat dihandle oleh Exception Handling • Logical Error • Terjadi karena kesalahan logika pemrogramman programmer • Kode harus dimodifikasi ulang • Biasanya terdeteksi ketika melakukan test atau debugging

  13. Exception Handling • Penanganan error untuk unexpected condition • Exception di manage oleh masing-masing Namespace • Exception Class merupakan Base Class untuk semua jenis Exception • Struktur Catch dapat bertingkat • Jenis Exception yang pertama harus lebih spesifik • Perintah Finally sifatnya opsional • Kode yang terdapat di dalam block Finally selalu dieksekusi

  14. StructureException Handling • Try … Catch ex As OverflowException … Catch ex As Exception … Finally ‘ (Optional) … End Try

More Related