Membuat Project
Setiap memulai project baru di VB6 kita akan selalu mendapat pertanyaan tentang project apa yang akan kita buat. Umumnya kita membuat "standard EXE". Pilihan ini akan membuatkan kita form baru kosong yang standar.
Tinjauan IDE
1. Kotak Menu : Berisi menumenu yang memiliki bermacam-macam pilihan. 2. Toolbox : Berisi object yang bisa ditempatkan di form 3. Window ini berisi object grafis seperti form atau user control 4. Object Grafis : Berisi object yang nantinya merupakan bagaimana tampilan program saat dijalankan
5. Project Toolbar : Tempat navigasi file-file project kita 6. Properties Window : digunakan untuk mengubah properti dari object-object.
Mengganti Properties
Jika kita klik pada object yang ada di form atau form-nya sendiri, kita akan bisa merubah properties dari item tersebut dan kita bisa mengubahnya pada panel propertis pada sisi kanan layar IDE.
DEMO!
DEMO!
Contoh penamaan File : OddCalc.vbp frmMain.frm frmAbout.frm frmPrintInvoice.frm modMain.bas modSettings.bas modDeclares.bas clsWinsock.cls
Variable
Syarat penamaan variable : Maksimal 255 karakter Tidak boleh ada spasi Tidak boleh dimulai dengan angka Tidak boleh ada titik Contoh :
Dim strName as String ' Declares a string called strName strName = "Billy Bob" ' Sets the value of strName strName = strName & " Thornton" ' Appends " Thornton" to strName MsgBox strName ' Outputs the value of strName to a Message Box
Variable Scope
5. Conditional statement
6. Loop 7. Function dan subroutine
Operator Pembanding
Equality "=" Syntax: P = Q
Operator Logika
Not
P True False Not P False True
And
Or
Statemen IF
If - Then
If <Expression> Then <Line of code to execute> --OR-- If <Expression> Then <Multiple lines of code to execute> End If
Statemen IF
If - Then - Else
If <Expression> Then <Code to execute if True> Else <Code to execute if False> End If
Statemen IF
If - Then - Elseif If <Expression1> Then <Code to execute if Expression1 is True> ElseIf <Expression2> Then <Code to execute if Expression1 is False and Expression2 is True> ElseIf <Expression3> Then <Code to execute if Expression1 and Expression2 are False, but Expression3 is True> Else <Code to execute if neither Expression1, Expression2 nor Expression3 is True> End If
Statemen IF
Contoh Public Sub Main() Dim S1 As String, S2 As String S1 = "Foo" S2 = "BAR" Dim X As Integer X = 0 If X < 5 Then Debug.Print "X is less than 5" If X > 3 Then Debug.Print "X is greater than 3." Else X = 3 Debug.Print "The value of X was changed from 0 to 3" End If If S1 = "FOO" Then If S2 <> "BAR" Then Debug.Print "S2 is not BAR." ElseIf (X > 0 And X <= 3) And (S2 = "BAR") Then Debug.Print "X is greater than 0 and less than or equal to 3, and _ S2 = 'BAR'." ElseIf X = 3 Then Debug.Print "X is 3 and S2 is not BAR." Else End End If End If End Sub
6. Loop
7. Function dan subroutine
Loops
Do - Loop / Exit Do
Do <Code to execute> Loop
Contoh :
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do Debug.Print X X = Y + X Y = X - Y If cnt >= 8 Then Exit Do Else cnt = cnt + 1 End If Loop End Sub
Loops
Do - Until Do Until <Expression> <Code to execute> Loop
Contoh
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do Until cnt >= 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub
Loops
Do - While Do While <Expression> <Code to execute> Loop
Contoh
Public Sub Main() Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. cnt = 1 Do While cnt < 8 Debug.Print X X = Y + X Y = X - Y cnt = cnt + 1 Loop End Sub
Loops
For - Next / Exit For / Step Dim I As Integer For I = <Integer> To <Integer> <Code to execute> Next
Contoh
Public Sub Main()
Dim X As Integer Dim Y As Integer Dim cnt As Integer 'Our counter. For cnt = 1 To 8 Debug.Print X X = Y + X Y = X - Y Next For I = 20 To 0 Step -2 Debug.Print I Next IEnd Sub