You are on page 1of 21

IfThen Select Case

Comparison Operator
= <> > < >= <=

Equal to Not equal to Greater than Less than Greater than or equal to Less than or equal to

Conditional Expression
10 <> 20 Score < 20 Score = Label1.Text

True (10 is nor equal to 20) True if Score is less than 20; otherwise, False True if the Text property of the label1 object contains the same value as the Score variable; otherwise, False True if the word Bill is in the first ext box; otherwise, False

TextBox1.Text = Bill

To evaluate a condition in the program and take a course of action based on the result.
If condition Then statement

condition = conditional expression statement = a valid VB program statement

If Score >= 20 Then LabelText1.Text = You Win!

this sort of comparison always result in True or False, never result in maybe

Logical Operato Meaning r

And If both conditional expression is True, then the result is True If either conditional expression is True, then the result is True If the conditional expression is False, then the result is True. If the conditional expression is True, then the result is False. If one and only one of the conditional expressions is True, then the result is True. If both are True or both are False, then the result is False.

Logical Operator


Vehicle = Bike And Price < True 300 Vehicle = Car Or Price < 500 Not Price < 100 Vehicle = Bike Xor Price < 300 True True False



Xor (exclusi ve Or)


Dim HumanAge As Integer HumanAge = 7 One year for a dog = seven years for a human If HumanAge <> 0 AndAlso 7/HumanAge <= 1 Then MsgBox(You are at least one dog year old) Else MsgBox(You are less than one dog year old) End if

Similar to IfThenElseIf, but more efficient when the branching depends on 1 test case.
Select Case variable Case value1 Statements executed if value1 matches variables Case value2 Statements executed if value2 matches variables . Case Else Statements executed if no matches found End Select

Mouse Event Handler

Select Case

Select Case Age

End Select

Case Is < 13 Label1.Text = Enjoy your youth! Case 13 To 19 Label1.Text = Enjoy your teens! Case 21 Label1.Text = Sweet 21! Case Is > 100 Label1.Text = Looking Good! Case Else Label1.Text = Thats a nice age to be.

Can execute a specific group of program statements a set of times in an event procedure or a code module. A short way of writing a long list of program statement because each group of statement in such a list does essentially the same thing, user can define just one group of statements and request that it be executed as many times as you want.


For variable = start To end


Statement to be repeated Next [variable]

entry Statement1 yes
n > 10

Dim i As Integer For i = 1 To 4 Beep() Next i Output ---> Beep() Beep() Beep() Beep()

No Statements

n = x + 1 exit

Chr(13) --> move to the beginning of line Chr(10) --> move to the next line

Private Sub Command1_Click() Dim strName As String strName = UCase(Text1.Text) For i = 1 To 5 FontSize = 10 + i If strName = keluar" Then Exit For Print strName; " "; i Next i End Sub






Alternative to ForNext loops Execute a group of statement until a certain condition is True Syntax :
Do while condition Loop

block of statements to be executed

Eg1: Dim InpName As String Do While InpName <> Done InpName = InputBox(Enter your name or type Done to quit) If InpName <> Done Then TextBox1.Text = InpName Loop Eg2: Dim InpName As String Do InpName = InputBox(Enter your name or type Done to quit) If InpName <> Done Then TextBox1.Text = InpName Loop While InpName <> Done

It is important to design your test condition so that each loop has a true exit point. Example:
Dim Number As Double Do Number = InputBox(Enter a number to square. Type -1 to quit) Number = Number * Number TextBox1.Text = Number Loop While Number >= 0


Rata-rata kita menuturkan 5000 perkataan setiap hari (walaupun 80% kita hanya bercakap pada diri sendiri Jika anda terbersin terlalu kuat, anda dapat meretakkan tulang rusuk. Jika anda cuba menahan bersin, anda boleh menyebabkan pembuluh darah di kepala dan leher pecah, dan menyebabkan kematian. Jika memaksa mata terbuka waktu Bersin bola mata boleh terkeluar dari tempantnya

Kita menyambut ulang tahun bersama 9 juta orang dari seluruh dunia
Kutu rambut sebenarnya lebih suka hidup di kulit kepala yang bersih daripada yang kotor Orang yang menggunakan tangan kanan, kira-kira, 9 tahun lebih panjang umur dari orang kidal Vitamin pada buah biasanya terdapat pada kulitnya