Instruksi pencabangan pada VBA ada dua pilihan yaitu: If Then Else dan Select Case. Instruksi If Then lebih efektif untuk pencabangan dengan sedikit pilihan (misalnya 2 atau 3 pilihan saja), sedangkan instruksi Select Case Else akan efektif untuk pencabangan dengan banyak pilihan.
Misal:
Dim Aksi As String
If Lampu = "Merah" Then
Aksi = "Berhenti"
End If
If Lampu = "Kuning" Then
Aksi = "Bersiap"
End If
If Lampu = "Hijau" Then
Aksi = "Jalan"
End If
'-------------------------
Dapat dituliskan dengan Select Case, sebagai berikut:
Dim Aksi As String
Select Case Lampu
Case "Merah"
Aksi = "Berhenti"
Case "Kuning"
Aksi = "Bersiap"
Case "Hijau"
Aksi = "Jalan"
End Select
'-------------------------
Atau bisa juga dilakukan pengecekan bertingkat seperti:
Dim Aksi As String
If Lampu = "Merah" Then
Aksi = "Berhenti"
Else
If Lampu = "Kuning" Then
Aksi = "Bersiap"
Else
If Lampu = "Hijau" Then
Aksi = "Jalan"
Else
Aksi = "Periksa Ulang"
End If
End If
End If
'-------------------------
Dapat dituliskan dengan Select Case Else, sebagai berikut:
Dim Aksi As String
Select Case Lampu
Case "Merah"
Aksi = "Berhenti"
Case "Kuning"
Aksi = "Bersiap"
Case "Hijau"
Aksi = "Jalan"
Case Else
Aksi = "Periksa Ulang"
End Select
'-------------------------
Dari keempat contoh diatas terlihat jelas bahwa untuk pencabangan dengan opsi banyak instruksi Selesct Case Else jauh lebih efektif dibandingkan dengan If Then Else.
Selanjutnya silahkan anda coba agar dapat langsung mengetahui perbedaan dari kedua instruksi tersebut, selamat mencoba . . . have a nice day :-)
www.AstroDigi.com (Nino Guevara Ruwano)
true religion outlet, mulberry, lacoste pas cher, true religion jeans, nike air max, new balance pas cher, abercrombie and fitch, lululemon, hermes, nike blazer, longchamp pas cher, air force, vans pas cher, michael kors, nike free run uk, north face, sac guess, nike air max, air jordan pas cher, burberry, converse pas cher, north face, louboutin pas cher, nike air max, nike free, vanessa bruno, ralph lauren pas cher, sac longchamp, michael kors, ralph lauren uk, ray ban uk, air max, hollister, oakley pas cher, michael kors, hogan, tn pas cher, hollister pas cher, ray ban pas cher, nike roshe run, true religion jeans, timberland
wedding dresses, soccer jerseys, nike roshe, abercrombie and fitch, iphone 6 cases, ferragamo shoes, reebok shoes, soccer shoes, ghd, asics running shoes, nike huarache, lululemon, vans shoes, instyler, nike roshe, oakley, insanity workout, p90x workout, mcm handbags, north face outlet, beats by dre, celine handbags, bottega veneta, baseball bats, north face outlet, longchamp, giuseppe zanotti, hollister, valentino shoes, new balance, nfl jerseys, hollister, jimmy choo shoes, babyliss, herve leger, mac cosmetics, birkin bag, timberland boots, chi flat iron, nike trainers, mont blanc, nike air max
cheap nike shoes
cheap oakley sunglasses
salomon shoes
adidas nmd
tiffany and co
los angeles lakers jerseys
san antonio spurs jerseys
green bay packers jerseys
gucci sito ufficiale
oakley sunglasses
20180712 xiaoou
moncler coats
coach outlet store
ralph lauren shirts
nike shoes outlet
swarovski outlet store
fitflops
ysl outlet online
moncler outlet
undefeated shoes
coach outlet