Satu Kondisi : IF ... THEN ...
Pada kondisi ini jika kondisi satu terpenuhi maka code result akan dijalankan atau dieksekusi. Namun
jika tidak memenuhi kondisi maka tidak ada yang dieksekusi.
Sintaks:
If [kondisi] Then [Result]
(2 atau lebih baris result)
If [kondisi] Then [Result] [Result] ...End If
Contoh:
UI:
Code :
Public Class Form1
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If i < 10 Then
i = i + 1
Label1.Text = i
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
If i > 0 Then i = i - 1 : Label1.Text = i
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
i = 0
Label1.Text = i
Button1.Text = "Tambah (+)"
Button2.Text = "Kurang (-)"
End Sub
End Class Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If i < 10 Then i = i + 1 Label1.Text = i End If End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click If i > 0 Then i = i - 1 : Label1.Text = i End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load i = 0 Label1.Text = i Button1.Text = "Tambah (+)" Button2.Text = "Kurang (-)" End Sub
End Class
Runtime :
Silahkan anda coba di komputer anda, dan ikuti terus pembelajaran kami selanjutnya...
0 komentar:
Posting Komentar