Pelajaran Visual Basic MsgBox & if then else

Pelajaran Syntax Visual basic MsgBox
BAB MsgBox

Berfungsi untuk menampilkan pesan pada kotak dialog
Syntax dasar;
MsgBox (prompt [, buttons] [, tittle]
                             [, helpfile, context])

Keterangan;
Parameter buttons dapat di isi dengan ;
vbOKOnly, menampilkan hanya tombol OK
vbOKCancel, menampilkan tombol OK dan Cancel
vbAbortRetryIgnore, menampilkan tombol Abort, Retry, Ignore
vbYesNoCancel, menampilkan tombol Yes, No, Cancel
vbYesNo, menampilkan tombol Yes dan No
vbRetryCancel, menampilkan tombol Retry dan cancel

Parameter Buttons;
vbCritical = X
vbQuestion = ?
vbExclamation = !
vbInformation = i

Contohnya;
Private Sub Command1_Click()
MsgBox "Kolom email harus di isi ",_vbExclamation, "Peringatan"
End Sub

BAB If then Else

Berfungsi sebagai statemen kondisi yakni sebuah kode atau blok kode akan dijalankan apabila kondisi terpenuhi (true) dan blok kode lainnya akan dijalankan apabila kondisi tidak terpenuhi (false)
Syntax Dasar 1:
If condition1 then statement
Contohnya;
if nilai_angka>=80 Then nilai_huruf = "A"

Syntax Dasar 2;
If condition1 Then statement
End if

Contohnya;
If nilai_angka>= 80 Then
nilai_huruf = "A"
MsgBox "Selamat Anda mendapat nilai terbaik", vbInformation, "Informasi
End If


Syntax Dasar 3;
If condition1 Then statement
else
statement
end if

Contohnya ;
If nilai angka >= 80 Then nilai_huruf="A"
MsgBox "Selamat Anda mendapat nilai terbaik",vbInformation, "Informasi"
End If

Syntax dasar 4;
If condition1 Then statement
Elseif condition2 Then Statement
End If

Contoh:
If nilai_angka >= 80 Then nilai_huruf = "A"
MsgBox "Selamat Anda mendapat nilai terbaik",vbInformation, "Informasi"
Elself nilai_angka >= 70 Then nilai_huruf ="b"
MsgBox "Nilai Anda baik", vbInformation, "Informasi"
Else
MsgBox"Nilai Anda Kurang",vbInformation, "Informasi"

BAB DO...LOOPS

Berfungsi sebagai statement perulangan.
Syntax Dasar 1;
Do until (Expression)
(code to execute)
Loop

Contohnya;
Dim i As Integer  
i=0
Do Until i = 100
i=i+i
Loop

Syntax Dasar 2;
Do while (Expression)
(Code to execute)
Loop

Contohnya;
Dim i As Integer
Do while i <= 100
i=i+1
Loop

Syntax Dasar 3;
Do 
(Code to execute)
Loop While (Expression)
Contohnya;
Dim i As Integer
Do
i=i+1
Loop While i <=100

BAB For...Next

Berfungsi sebagai Statemen perulangan
Syntax Dasar;
For counter=Start To end [step step]
(code to execute)
Next [counter]

Contohnya ;
Dim i As Integer
For i = 0 To 10
MsgBox "Nilai i = " & i
Next i

Contohnya yang kedua ;
Dim i As Integer
For i = 0 To 10 step 2
MsgBox "Nilai i = " & i
Next i

 

Komentar