Minggu, 26 Desember 2010

Syntax Dasar Visual Basic 6.0 (1)

Ini ada beberapa Syntax dasar Visual Basic 6.0 beserta contohnya semoga bermanfaat,
dan ini bagian pertama dari artikel ini...
1. MsgBox
digunakan untuk menampilkan pesan pada kotak dialog.
Syntax dasar :
Msgbox (prompt[,buttons][,title][,helpfile][,context]

parameter buttons dapat diisi 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, No.
vbRetyCancel, menampilkan tombol Retry dan Cancel.

contoh :
Private Sub Command1_Click()
MsgBox "Hanya di infoislam99.blogspot.com", vbOKOnly, "Info Islam"
End Sub
Hasil :







2. If....Then....Else
Digunakan sebagai statemen kondisi. sebuah kode/blok kode akan dijalankan apabila kondisi terpenuhi (true), dan blok kode lainnya akan dijalankan apabila kondisinya tidak terpenuhi (false).
Syntax 1:
If condition1 then statement

contoh:
If nilai_angka >= 80 Then nilai_huruf = "A"

Syntax 2 :
If condition1 then
statement
end if

Contoh:
If niali_angka >= 80 then
nilai huruf = "A"
Msgbox "selamat anda mendapatkan nilai terbaik",vbOkOnly,"Informasi"
end if

Syntax 3:
If condition1 then
statement
else
statement
end if

Contoh :
If nilai_angka >= 80 then
nilai_huruf = "A"
else
nilai_huruf = "B"
end if

Sintax 4:
If condition1 then
statement
elseif condition2 then
statement
else
statement
end if

contoh :
If nilai_angka >= 80 then
nilai_huruf = "A"
elseif nilai_angka >= 70 then
nilai_huruf = "B"
else
nilai_huruf = "C"
end if

3. Do... Loops
Digunakan sebagai statenent perulangan.

Syntax 1:
Do Until (Expression)
(code to execute)
Loop

Contoh :
Dim i as integer
i = 0
Do until i = 100
i= i +1
loop

Syntax 2 :
Do While (Expression)
(code to execute)
Loop

Contoh :
Dim i as integer
do while i <= 100
i = i+1
loop

Syntax 3 :
Do
(code to execute)
Loop while (expression)

contoh :
Dim i as integer
Do
i = i +1
Loop while i <= 100

4. For.. Next
Digunakan sebagai statement perulangan

Syntax dasar :
For counter = start to end ( Step step)
(code to execute)
Next (counter)

Contoh :
Dim i as integer
For i = 0 to 10
msgbox "Nilai i = " & i
next i

5. Select Case
Digunakan sebagai statement kondisi dengan banyak pilihan.

Select Case nilai_angka
Case 0 to 50
nilai huruf = "D"
Case Is <= 70
nilai huruf ="C"
Case Is <= 80
nilai huruf = "B"
Else Case
nilai huruf = "A"
End select
Msgbox "nilai huruf = " & nilai_huruf

0 komentar:

Posting Komentar | Feed

Posting Komentar



 

jawe99 Copyright © 2009 Premium Blogger Dashboard Designed by SAER