Minggu, 12 Desember 2010

Visual Basic (percabangan)

Percabangan
1. If .... end if
Syntax :
If then
...
elseif then
...
else
...
End if
contoh :
If text1=”L” then
jenkel=”laki-laki”
else
jenkel=”perempuan”
end if

2. Select Case ...end case
Syntax:

Select case
case
case
else case
end select
Contoh :
Select case angka
Case 4
huruf=”A”
Case 3
huruf=”B”
Case 2
huruf=”C”
Case 1
huruf=”D”
Else case
huruf=”E”
End select

Perulangan

1. for...next
Perulangan proses menggunakan For…Next adalah bentuk pengulangan terkendali dengan variabel kendali yang terus berjalan maju atau mundur.
syntax:

for = to step
...
Next []

Contoh :
Dim i%
For i=1 to 5
Print i
Next i
2. do until ... loop
syntax:
do until
...
loop
contoh:
Dim i%
Do until i<5
Print i
i=i+1
loop
3. do while...loop
syntax:

do while
...
loop
contoh:
Dim i%
Do while i<=5
Print i
i=i+1
loop

4. while ...wend
Perulangan dengan While... Wend adalah bentuk pengulangan terkendali dengan proses akan diulang selama kondisi yang diberikan masih dipenuhi.
syntax:

while
...
Wend1
Contoh :
Dim i%
while i<=5
Print i
i=i+1
wend

0 komentar:

Posting Komentar